Skip to content

Fixes: #35 support i18n#74

Closed
erundle wants to merge 1 commit into
patternfly:masterfrom
erundle:master
Closed

Fixes: #35 support i18n#74
erundle wants to merge 1 commit into
patternfly:masterfrom
erundle:master

Conversation

@erundle
Copy link
Copy Markdown

@erundle erundle commented Sep 8, 2015

Handles basic string replacement. Assumes products translate strings and pass in via lang object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is an optional param, then it should be:

@param {object=} lang translated i18n strings

@dtaylor113
Copy link
Copy Markdown
Member

Is this just a PR to get the coding pattern approved, and then it will be applied to the other charts?

@dtaylor113
Copy link
Copy Markdown
Member

Other than those issues, LGTM

@erundle
Copy link
Copy Markdown
Author

erundle commented Sep 8, 2015

Yes I wanted to show the concept and if we think it makes sense I will apply this to other directives.

@waldenraines
Copy link
Copy Markdown

I personally think we should use the strings themselves as keys and pass them into a translation service (or a directive that uses the service in the case of html).

We could use angular-gettext for this. The user would just have to provide the translation.js file (example of the grunt generated angular-gettext file), which populates a map between the keys (the actual words) and the translations. This translation service replaces the strings with the user-provided translations based on $locale.

I don't think we want to force the user to set every single string they want translated via a javascript object in the code that uses the angular-patternfly component. This quickly becomes cumbersome:

$scope.lang = {
  available: 'Disponible',
  notAvailable: 'No disponible',
  yes: 'si',
  no: 'no'  
};

Instead we should encourage users to use .po files (pretty much the standard for i18n) and generate a javascript dictionary from that. This approach also has the added benefit of falling back to English in the case that a translation is not found instead of resolving to undefined or resulting in an error.

Also, how would the implementation here support plurals? What about languages with more than one plural form? Using an existing translation library handles these issues for you.

@erundle
Copy link
Copy Markdown
Author

erundle commented Sep 8, 2015

I am not completely against using existing translation but the parent application will need to tell us what language to use. We also need to make sure we can bootstrap multiple translation libraries (I have seen this be an issue in angular applications in the past where we actually had to merge translation files since config was done as a singleton). As far as .po files vs. json when it comes to client side libraries JSON seems to be the new norm:
https://angular-translate.github.io/
http://i18next.com/

@erundle
Copy link
Copy Markdown
Author

erundle commented Sep 8, 2015

Also the beautiful part of not doing the actual translation is products can add languages based on their needs so we don't need to provide translations for every language out there and if a product wants to easily change a string value they can. If they want to use "Free" vs. "Available" vs. "Not Used" vs. "Whatever" they are free to customize things from a terminology perspective as they see fit.

@jeff-phillips-18
Copy link
Copy Markdown
Member

I too believe the approach here is too cumbersome.

Could we use something like I18Next and require the application to set the locale? We could use I18Next for all of our strings and provide the appropriate translation files. If the application wanted to use some other library they could . Strings passed to our directives could be pre-translated or they could be keys.

Granted it would be easier to not have to provide translations. I just think requiring applications to pass in lang objects for every string we want to present is a bit overbearing and if we change how we present strings or which strings we present then the applications would need to change.

@waldenraines
Copy link
Copy Markdown

We also need to make sure we can bootstrap multiple translation libraries

That's a good point. I'm not opposed to writing something ourselves but I do think that the translations should be done via a service/directive instead of with plain JS objects.

As far as .po files vs. json when it comes to client side libraries JSON seems to be the new norm:
https://angular-translate.github.io/
http://i18next.com/

i18next supports gettext and I'd argue that angular-translate is a bad implementation. In addition to not supporting .po files it also requires made up IDs for the translation dictionary, and it uses filters instead of directives which is not as performant.

We could just write a simple service that reads in a JSON file (to be provided by the consuming project via whatever way they want) and then looks up values in that file based on $locale.

{
    "es": {
        "yes": "",
        "no": "no"
    },
    "fr": {
        "yes": "oui",
        "no": "non"
    }
}
<p i18n>Yes</p>
var yes = i18n('yes');

Although we would still have to consider how to handle plurals...

@waldenraines
Copy link
Copy Markdown

Also the beautiful part of not doing the actual translation is products can add languages based on their needs so we don't need to provide translations for every language out there and if a product wants to easily change a string value they can. If they want to use "Free" vs. "Available" vs. "Not Used" vs. "Whatever" they are free to customize things from a terminology perspective as they see fit.

I agree, and I was not suggesting that we should do our own translations, just that we should create an easier way for the consumer to provide the translations.

@erundle
Copy link
Copy Markdown
Author

erundle commented Sep 8, 2015

FYI this handles plurals https://docs.angularjs.org/api/ng/directive/ngPluralize

@waldenraines
Copy link
Copy Markdown

FYI this handles plurals https://docs.angularjs.org/api/ng/directive/ngPluralize

Sort of, you still have to mark the string for translation and then override the localization rules, check out the first paragraph on that page:

ngPluralize is a directive that displays messages according to en-US localization rules. These rules are bundled with angular.js, but can be overridden (see Angular i18n dev guide). You configure ngPluralize directive by specifying the mappings between plural categories and the strings to be displayed.

@erundle
Copy link
Copy Markdown
Author

erundle commented Sep 9, 2015

Please let me know if anyone has an objection to using this. I started to write my own provider etc to wrap i18next and then I realized that was silly. I think i18next is our best bet so I was thinking of adding this as well: https://github.com/i18next/ng-i18next. I have this plugged in and working now but I wanted to see if anyone had any major push back before I went further. Pending everyone thinks that makes sense I will close this PR and open up a new one once I am ready.

@jeff-phillips-18
Copy link
Copy Markdown
Member

I agree with that approach.

@waldenraines
Copy link
Copy Markdown

I think i18next is our best bet

I agree since it allows for both JSON and gettext (looks like there is also grunt task for converting from gettext to i18next's JSON format).

Also, it seems that ng-i18next provides a filter which we can inject for translations within our JS code. This approach looks good to me from a quick glance, thanks for researching.

@dtaylor113
Copy link
Copy Markdown
Member

LGTM,
Thanks,

  • Dave

On Wed, Sep 9, 2015 at 12:58 PM, Eleni Rundle notifications@github.com
wrote:

Please let me know if anyone has an objection to using this. I started to
write my own provider etc to wrap i18next and then I realized that was
silly. I think i18next is our best bet so I was thinking of adding this as
well: https://github.com/i18next/ng-i18next. I have this plugged in and
working now but I wanted to see if anyone had any major push back before I
went further. Pending everyone thinks that makes sense I will close this PR
and open up a new one once I am ready.


Reply to this email directly or view it on GitHub
#74 (comment)
.

Dave Taylor
Principle Software Engineer
(978) 392 - 1016

@erundle erundle closed this Sep 9, 2015
@erundle erundle mentioned this pull request Sep 15, 2015
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

Successfully merging this pull request may close these issues.

4 participants