-
Notifications
You must be signed in to change notification settings - Fork 154
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
Language fallbacks #250
Language fallbacks #250
Conversation
Closes rubenv#210
- baseLanguage is private because it conflicts with catalog's attribute with the same name - plural detection is pretty hardcoded, there's no clear way to know if plural is defined or not
…ew function Removes getStringForm(). See discussion here: rubenv#236 (comment)
} | ||
return null; | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be executed a lot. I suggest adding a simple memoization:
angular.module("gettext").factory("gettextFallbackLanguage", function () {
var cache = {};
var pattern = /([^_]+)_[^_]+$/;
return function (langCode) {
if (cache[langCode]) {
return cache[langCode];
}
var matches = pattern.exec(langCode);
if (matches){
cache[langCode] = matches[1];
return matches[1];
}
return null;
};
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Added.
Credit goes to rubenv rubenv#250 (diff)
Last few things fixed – all ready for merge then? |
This looks excellent, I will put this through some testing on our projects. If it doesn't throw up any problems (not expecting any), it'll get merged. |
Great! Let me know :) |
Works like a charm! |
Released as This one still needs updating: https://angular-gettext.rocketeer.be/dev-guide/api/angular-gettext/ (website is in git here: https://github.com/rubenv/angular-gettext-website). I'll do that myself in a minute. Thanks, a lot! |
Great work guys. Thanks. |
Makes languages fall back onto their base language:
en_GB
→en
,de_CH
→de
, etc.› Original issue: #210
› Original PR: #236
Notable changes:
getStringForm()
gettextFallbackLanguage()
methodLet me know if you have any better suggestions for better naming, or if there is anything else that could be improved upon.