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

Handling untranslated entries in ttag lib #111

Closed
MrOrz opened this issue May 10, 2018 · 1 comment
Closed

Handling untranslated entries in ttag lib #111

MrOrz opened this issue May 10, 2018 · 1 comment

Comments

@MrOrz
Copy link
Contributor

MrOrz commented May 10, 2018

I am setting up webpack with ttag under development environments.

I found that the way ttag lib handles untranslated entries (i.e. msgstr "") is different from the way babel-plugin-ttag does. In babel-plugin-ttag, it resolves to default locale by default; however, ttag lib just resolves to empty strings.

Since gettext-parser.po() does not provide us ways to filter out untranslated entries, I think we should handle this within ttag lib.

There are 2 ways to handle untranslated entries:

  1. modify the implementation of t, jt, gettext, ngettext in ttag lib to match the implementation of babel-plugin-ttag/resolve.js's no-translation handling.
  2. modify the implementation of addLocale(locale, poData) so that it filters out untranslated entries within poData. This involves changing the logic of transformTranslateObj(translationObj) in utils.js

Personally I prefer method 2 because it is simpler, but method 1 provides more flexibility -- we can implement no-translation warnings / errors similar to babel-plugin-ttag's if we use method 1.

I am happy to send PR for this, but I would like to ask for your opinion on choosing method 1 or method 2.

@AlexMost
Copy link
Member

AlexMost commented May 10, 2018

You are right, that behavior must be consistent. Seems like we can fix that with adding one extra check to findTransObj here - https://github.com/ttag-org/ttag/blob/master/src/index.js#L38.

Here is a similar check in the babel plugin

export function hasTranslations(translationObj) {
    return translationObj[PO_PRIMITIVES.MSGSTR].reduce((r, t) => r && t.length, true);
}

Would be great if you will send a PR!

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

2 participants