discourse/app/assets/javascripts/locales
Godfrey Chan 2e00482ac4
DEV: convert I18n pseudo package into real package (discourse-i18n) (#23867)
Currently, `window.I18n` is defined in an old school hand written
script, inlined into locale/*.js by the Rails asset pipeline, and
then the global variable is shimmed into a pseudo AMD module later
in `module-shims.js`.

This approach has some problems – for one thing, when we add a new
V2 addon (e.g. in #23859), Embroider/Webpack is stricter about its
dependencies and won't let you `import from "I18n";` when `"I18n"`
isn't listed as one of its `dependencies` or `peerDependencies`.

This moves `I18n` into a real package – `discourse-i18n`. (I was
originally planning to keep the `I18n` name since it's a private
package anyway, but NPM packages are supposed to have lower case
names and that may cause problems with other tools.)

This package defines and exports a regular class, but also defines
the default global instance for backwards compatibility. We should
use the exported class in tests to make one-off instances without
mutating the global instance and having to clean it up after the
test run. However, I did not attempt that refactor in this PR.

Since `discourse-i18n` is now included by the app, the locale
scripts needs to be loaded after the app chunks. Since no "real"
work happens until later on when we kick things off in the boot
script, the order in which the script tags appear shouldn't be a
problem. Alternatively, we can rework the locale bundles to be more
lazy like everything else, and require/import them into the app.

I avoided renaming the imports in this commit since that would be
quite noisy and drowns out the actual changes here. Instead, I used
a Webpack alias to redirect the current `"I18n"` import to the new
package for the time being. In a separate commit later on, I'll
rename all the imports in oneshot and remove the alias. As always,
plugins and the legacy bundles (admin/wizard) still relies on the
runtime AMD shims regardless.

For the most part, I avoided refactoring the actual I18n code too
much other than making it a class, and some light stuff like `var`
into `let`.

However, now that it is in a reasonable format to work with (no
longer inside the global script context!) it may also be a good
opportunity to refactor and make clear what is intended to be
public API vs internal implementation details.

Speaking of, I took the librety to make `PLACEHOLDER`, `SEPARATOR`
and `I18nMissingInterpolationArgument` actual constants since it
seemed pretty clear to me those were just previously stashed on to
the `I18n` global to avoid polluting the global namespace, rather
than something we expect the consumers to set/replace.
2023-10-12 14:44:01 +01:00
..
ar.js.erb UX: Make moment.js produce Arabic numerals instead of Hindi numerals in the Arabic locale (#11788) 2021-01-21 22:11:51 +03:00
be.js.erb
bg.js.erb
bs_BA.js.erb
ca.js.erb
cs.js.erb
da.js.erb
de.js.erb
el.js.erb
en.js.erb
en_GB.js.erb FEATURE: Add English (UK) as locale (#11768) 2021-01-20 21:32:22 +01:00
es.js.erb
et.js.erb
fa_IR.js.erb
fi.js.erb
fr.js.erb
gl.js.erb
he.js.erb
hr.js.erb FEATURE: Add Croatian language (#17130) 2022-06-18 00:18:22 +02:00
hu.js.erb
hy.js.erb
i18n.js DEV: convert I18n pseudo package into real package (discourse-i18n) (#23867) 2023-10-12 14:44:01 +01:00
id.js.erb
it.js.erb
ja.js.erb
ko.js.erb
lt.js.erb
lv.js.erb
nb_NO.js.erb
nl.js.erb
pl_PL.js.erb
pt.js.erb
pt_BR.js.erb
ro.js.erb
ru.js.erb
sk.js.erb
sl.js.erb
sq.js.erb
sr.js.erb
sv.js.erb
sw.js.erb
te.js.erb
th.js.erb
tr_TR.js.erb
uk.js.erb
ur.js.erb
vi.js.erb
zh_CN.js.erb
zh_TW.js.erb