Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Copy message ID to translation for source locale #141

Closed
fohrloop opened this issue Dec 17, 2017 · 4 comments
Closed

Suggestion: Copy message ID to translation for source locale #141

fohrloop opened this issue Dec 17, 2017 · 4 comments
Milestone

Comments

@fohrloop
Copy link

The lingui extract --format minimal command makes pretty messages.json files, like this:

{
  "This is a test": "",
  "{messagesCount, plural, one {There's # message in your inbox} other {There're # messages in your inbox}}": ""
}

Suggestion

A flag called --default-translation or similar, which could be used like lingui extract --format minimal --default-translation en_US, which would produce

{
  "This is a test": "This is a test",
  "{messagesCount, plural, one {There's # message in your inbox} other {There're # messages in your inbox}}": "{messagesCount, plural, one {There's # message in your inbox} other {There're # messages in your inbox}}"
}

into locale/en_US/messages.json, to enhance translation experience.

Reasoning

(1) Some translation tools might give false alarms of missing translations, if there are empty fields.
(2) If someday there will be optimized message ID's (#139), translating these

// locale/en_US/messages.json
{
  "1": "This is a test",
  "2": "{messagesCount, plural, one {There's # message in your inbox} other {There're # messages in your inbox}}"
}
// locale/fi_FI/messages.json
{
  "1": "",
  "2": ""
}

will be more pleasant than translating these:

// locale/en_US/messages.json
{
  "1": "",
  "2": ""
}
// locale/fi_FI/messages.json
{
  "1": "",
  "2": ""
}
@tricoder42
Copy link
Contributor

I think we could use existing sourceLocale config, but instead of handling source locale in lingui extract and lingui compile commands as described here, we could copy message IDs in lingui extract command.

My original idea was that catalog for sourceLocale could be completely ignored, but you're right that it may still be requird for external tools.

As for (2), message ID optimization should be done in compilation step. messages.json should always have full message IDs. This way we can change message ID optimization anytime without breaking translations in 3rd party tools which rely on immutable message IDs.

What do you think?

@fohrloop
Copy link
Author

Using sourceLocale seems clever, since it is an existing configuration option. Copying message IDs in the lingui extract command solves the problem, and to me feels the correct path. I don't know would it make someone upset to see their sourceLocale languages message IDs (untranslated text) to be copied into the translation by default? If it would, then we could add just a --no-copy option (flag or config option). But otherwise, I think copying should be the default behaviour. (since messages.json is just used in development anyway)

As for (2), message ID optimization should be done in compilation step. messages.json should always have full message IDs. This way we can change message ID optimization anytime without breaking translations in 3rd party tools which rely on immutable message IDs.

Thats exactly right. Better to keep message ID optimization in the compilation step! I don't know what I was thinking :)

@tricoder42
Copy link
Contributor

I don't know would it make someone upset to see their sourceLocale languages message IDs (untranslated text) to be copied into the translation by default?

In that case it's harder to check for missing translations. It make sense only for few locales and those usecases are covered by fallbackLocale (e.g. en_US could use translations from en_GB if missing).

@tricoder42 tricoder42 changed the title Suggestion: Option for lingui extract: "--default-translation" Suggestion: Copy message ID to translation for source locale Dec 23, 2017
@tricoder42 tricoder42 added this to the jsLingui 2.0 milestone Dec 23, 2017
@vsnig
Copy link

vsnig commented Mar 20, 2018

Is it unusable with custom message ids?

...
<Trans id="page.title">Hello World!</Trans>
...

(with "sourceLocale": "en" set in config)

extracts:
"page.title":"page.title" instead of "page.title": "Hello World!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants