How to localize text unknown at compile time?
See original GitHub issueProblem: A lot of our application text (or keys, that’s irrelevant in this case) comes from a backend. For example, enum types. We’d like to localize those texts too, and we can’t use i18nMark because, as discussed at #177, this content is unknown at compile time.
Question: Is there a way to solve this problem using linguijs? Or plans to support this in the future?
Feature request:
Given a fully automated solution seems unfeasible (beyond what was commented at https://github.com/lingui/js-lingui/issues/177#issuecomment-373749758), our current approach is to manually add entries (without an origin
) to the catalogs. However, in this case lingui extract
marks these entries as obsolete, so we risk deleting them whenever anyone runs lingui extract --clean
. Is it even acceptable to manually modify the catalog? Would it be possible to support adding manual entries to the catalog?
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (9 by maintainers)
Top GitHub Comments
I’m trying to say that my original proposal isn’t about loading locales, but only message definitions. No matter if messages are extracted from source files or remote API, first you always need just message definitions and then you create locale files by merging with existing catalogs. Yes, we could also add loading translations from API, but that’s another step.
In your case you would load message IDs and default values:
In gettext, the workflow was usually extract file with message definitions
messages.pot
(mind thepot
extension) from source files and then generate locale filesen.po
,cs.po
, etc.My idea here is similar: query API for message definitions only, because then we can guarantee that each locale files have the same messages (and warn user about missing translations, etc).
Reading from FS is synchronous at the moment, but we could change it to be async and then the messages from all sources would be loaded in parallel.
At the moment I’m implementing this RFC which improves
localeDir
config. I guess we could add support for a) static catalogs and b) catalogs loaded from scripts (e.g. query graphql backend)Something like:
Loading from script
Load message descriptors from local FS or remote API and export them.
lingui extract
will collect them and create a catalog for them, something like this:Generated
graphql.json
will look like this (depending onformat
, this isminimal
json, where values are translations):Static files
These files are basically ignored in
lingui extract
, but messages from them are used inlingui compile
.What do you think?