Moving i18n to webpack

We’re about to move Jed into webpack from assets pipeline (PR)

legacy javascript files

Jed will be deprecated from global access, use tfm instead:

Jed.sprintf('some %s', var);  // Deprecated !
tfm.i18n.translate('some string');
tfm.i18n.ngetext('sone string');
tfm.i18n.sprintf('some %s', var);

global __('') and n_('') won’t be deprecated yet.

Webpack files

Foreman core

import I18n.js which located in /webpack/assets/javascripts/react_app/common

import { 
translate as __,
ngettext as n_,
} from '../../../react_app/common/I18n';

Please do not use the global __(), n_ functions. Instead, use the imported translate(), ngettext()


In order to import I18n functions, use foremanReact alias:

import { 
translate as __,
ngettext as n_,
} from 'foremanReact/common/I18n';

This has been merged yesterday and would be part of 1.20.

This is quite a lot to write for every string. As long as we have legacy js code in core and plugins, i’d rather we keep the global __() and n__() available for translations.

Also, are the strings marked with the explicit function names extracted to to .po files? iirc our i18n process searches only for __() strings in the js code (and’ i’m not sure if it even searches the webpack folder, might need to verfy that as well).

that’s exactly why they are not deprecated, but in webpack code its easy to import the function and use it without a lot of typing. ideally, long term we don’t want to have JS code outside of webpack.

thats a good point!, and you are correct, as long as we keep using __ (or N__ etc) we are OK, see

@amirfefer I assume you should double check that tfm.i18n.__(…) works as expected (for extracting strings).

that was implemented long time ago (Bug #18213: Strings are not extracted from webpack folders. - Foreman)

I double checked and tfm.i18n.sprintf(_('') extracts strings to .po,
and __('') works under webpack as well.
however, tfm.i18n.translate('') does not .

Looking on the bright side, we do not use tfm.i18n.translate in legacy code, and under webpack we use __() alias for it, therefore .po files seems to be fine.

So that means that legacy code should continue using the __() functions rather than the tfm.i18n ones?
Please also update Translating - Foreman and Foreman :: Contribute accordingly.