WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #20491, comment 8


Ignore:
Timestamp:
07/20/2014 03:24:22 PM (7 years ago)
Author:
TV productions
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #20491, comment 8

    initial v1  
     1I think a good set of i18n javascript functions improves the javascript localisation, especially for plural sentences. So I have here a first "sketch" of those functions, primarily focussed on gettext for javascript. See it all at [https://github.com/TV-productions/WP-JS-GetText GitHub]. It is a small plugin that will show some translated messages from core if you activate it.
     2
    13How it works:
    24* It uses the Po/Mo files that are parsed in PHP to generate a structure that the javascript functions will use.
     
    911Possible drawbacks:
    1012* All the translated strings are always loaded: for the current core translations (textdomain 'default') is that about a 600KB script.
    11 * There has to be a JS function like sprintf to parse `%s`, `%d`, `%1$s`, etc. Possible starting point: [sprintf for js](https://github.com/kvz/phpjs/blob/master/functions/strings/sprintf.js)
     13* There has to be a JS function like sprintf to parse `%s`, `%d`, `%1$s`, etc. Possible starting point: [https://github.com/kvz/phpjs/blob/master/functions/strings/sprintf.js sprintf for js]
    1214* It uses the standard plural expression from gettext (for example `n!=1`), but this code is executed in js and maybe a security issue. the plural expression is currently filtered by a regular expression that removes all charters that shouldn't be in a plural expression, but it still is a bit tricky.
    1315