-
Notifications
You must be signed in to change notification settings - Fork 542
ui-I18n Proposal #173
ui-I18n Proposal #173
Conversation
Tim, can the ui.i18n module expose a service for doing all these things, rather than having properties that dangle off the module object? That would let us leverage DI, and would prevent issues with the module not existing when the language packs try to use it, depending on file execution order. |
This looks really nice. Any plans on parameter support? I mean something like "You have %1 credits left". |
@c0bra I added a service wrapper for the module syntax is the exact same except for a new method getCache() which returns the module _cache |
@waltersurf, right now if you want to format a string you can pipe it to a filter or use angular's builtin formatting for the result of the string. there shouldn't be anything preventing that. Can you play with it and see if you find any issues? |
Timothy, you're right it works fine like that. Having to use another filter adds some length to the syntax, but then again this is the more rare use case. Also this way the parameter markup is not dictated by the translation library, which is nice. |
fyi: I've rebased the angular-translate demo on the current 2.0.1: http://jsfiddle.net/knalli/f9fe8/1/ |
I'm the author of angular-localize, a localization implementation for AngularJS which focuses on the best possible performance. |
Would love to see some benchmarks here :) |
If someone wants to throw together a JSPerf comparison that would be cool. I don't have the time at the moment. This also focuses on being as lightweight as possible, such as not dictating any syntax for string formatting or pluralization since those are already features of angular. |
ng-pluralize falls short if you want to combine pluralization with gender selection. Both angular-translate and angular-localize make use of MessageFormat.js, which is based on a standard, allows precompilcation of the translation functions and is - based on my research looking at implementations of Gettext and various custom string replacement libraries - the best available solution for a flexible JavaScript localization implementation. I've created a console timed test for angular-localize here: The code used in the JSFiddle is also suitable for JSPerf, I've created one with a duplicate here: Generally though, I'm not sure if the JSPerf setup is the best way to analyze the performance. Btw., although I really recommend Messageformat, angular-localize is independent of this format, as it simply uses the provided translation functions. |
Can't this be merged still? impatiently waiting for that |
I updated this to work with Angular 1.3 + and also made it a provider to inject into .config blocks I also registered it as "angular-ui-i18n" on bower. |
This PR seems to be obsolete. Moreover UI.Utils modules was split in individuals repositories. If still valid, please consider re-submitting on the dedicated repository. See the README for details. |
due to the verbose nature of a couple of the i18n libraries out there and working on ng-grid 3.0 and wanting a lightweight version of i18n support I created a module that seems to be fairly lightweight and performant.
you can compare the performance of thousands of bindings against angular-translate here:
angular-translate 11K rows of bindings
ui-i18n 14K rows of bindings
setup:
NOTE: you can lazy load strings and it will extend the current set of strings with the new ones
You can set the language via directive
Or, through a module method:
Usage:
You can use it as an attribute, element, or filter, see all the different possibilities below
Bonus:
{{}} expressions work in the directive syntax also.
Caveat, this does impact performance a little bit.. even using this syntax its still about 2-3x faster than angular-translate with a similar amount of rows but you should know.
it will alert you to missing translations with "[MISSING]: invalid.path" in place of where the translations should be.
All feedback is greatly appreciated.
here is a plunk for your enjoyment:
ui-i18n plunk