i18n 💑 gettext

server browser
extract gettext jsxgettext
translate fast_gettext
gettext_i18n_rails
po2json/Jed

Solutions You Need to Know

Rails Portable

_('Car') == 'Auto'

_('not-found') == 'not-found'

s_('Namespace|not-found') == 'not-found'

n_('Axis','Axis',3) == 'Achsen'

_('Hello %{name}!') % {name: "Pete"} == 'Hello Pete!'

ActiveRecord Error Message

validates_presence_of :first_name, message: N_("Can\'t be blank")

jsxgettext 💔 Jed

What jsxgettext supports:

gettext("Hello world!");

gettext("Hello " + 'world!');

myModule.gettext("Hello " + 'world!');

gettext.call(myObj, "Hello " + 'world!');

ngettext("Here's an apple for you", "Here are %s apples for you", 3); ngettext("Here's an apple" + ' for you', "Here are %s apples" + ' for you', 3);

myModule.ngettext("Here's an apple" + ' for you', "Here are %s apples" + ' for you', 3);

ngettext.call(myObj, "Here's an apple" + ' for you', "Here are %s apples" + ' for you', 3);

What Jed supports:

gettext = function ( key )

dgettext = function ( domain, key )

dcgettext = function ( domain, key, category )

ngettext = function ( singular_key, plural_key, value )

dngettext = function ( domain, singular_ley, plural_key, value )

dcngettext = function ( domain, singular_key, plural_key, value, category )

pgettext = function ( context, key )

dpgettext = function ( domain, context, key )

npgettext = function ( context, singular_key, plural_key, value )

dnpgettext = function ( domain, context, singular_key, plural_key, value )

dcnpgettext = function ( domain, context, singular_key, plural_key, value, category )

Just simple: red-precious-stone-i18n-js

i18n.gettext('Car').value == 'Auto'

 

i18n.gettext('My car is %(brand)s').with({brand: 'ford'}) == 'My auto is ford'

 

i18n.ngettext('Car','Cars',3).value == 'Cars'

 

i18n.ngettext('buy a %(brand)s car','buy %(brand)s cars',3)

.with({brand: 'ford'}) == 'buy ford cars'

YAML pain-point

Regarding *.yml as *.erb

Command line tools & Known issues

rake gettext:add_language[en]

 

rake gettext:find

 

jsxgettext app.js -o app.po # need npm i -g, plural lost

 

po2json sample.po sample.json -p # need npm i -g, plural lost

Useful resources

https://github.com/grosser/gettext_i18n_rails

https://github.com/grosser/fast_gettext

https://github.com/mutoh/gettext

https://github.com/zaach/jsxgettext

https://github.com/SlexAxton/Jed/

i18n

By hanyi8000

i18n

  • 2,019