Skip to content

Commit

Permalink
rename fallbackLanguage to baseLanguage
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
crissdev committed Oct 30, 2015
1 parent dfa89d0 commit 3fdb714
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
17 changes: 10 additions & 7 deletions dist/angular-gettext.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "$http",
$rootScope.$broadcast('gettextLanguageChanged');
}

function fallbackLanguage(lang) {
var parts = (lang || '').split('_');
if (parts.length > 1) {
return parts[0];
function baseLanguage() {
if (catalog.currentLanguage) {
var parts = catalog.currentLanguage.split('_');
if (parts.length > 0) {
return parts[0];
}
return catalog.currentLanguage;
}
return null;
}
Expand Down Expand Up @@ -101,8 +104,7 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "$http",
},

getStringForm: function (string, n, context) {
var fallback = fallbackLanguage(this.currentLanguage);
var stringTable = this.strings[this.currentLanguage] || this.strings[fallback] || {};
var stringTable = this.strings[this.currentLanguage] || this.strings[baseLanguage()] || {};
var contexts = stringTable[string] || {};
var plurals = contexts[context || noContext] || [];
return plurals[n];
Expand All @@ -115,7 +117,8 @@ angular.module('gettext').factory('gettextCatalog', ["gettextPlurals", "$http",
},

getPlural: function (n, string, stringPlural, scope, context) {
var form = gettextPlurals(this.currentLanguage, n);
var baseLang = baseLanguage();
var form = gettextPlurals(this.currentLanguage !== 'pt_BR' ? baseLang : this.currentLanguage, n);
string = this.getStringForm(string, form, context) || prefixDebug(n === 1 ? string : stringPlural);
if (scope) {
scope.$count = n;
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-gettext.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, $h
$rootScope.$broadcast('gettextLanguageChanged');
}

function fallbackLanguage(lang) {
var parts = (lang || '').split('_');
if (parts.length > 1) {
return parts[0];
function baseLanguage() {
if (catalog.currentLanguage) {
var parts = catalog.currentLanguage.split('_');
if (parts.length > 0) {
return parts[0];
}
return catalog.currentLanguage;
}
return null;
}
Expand Down Expand Up @@ -89,8 +92,7 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, $h
},

getStringForm: function (string, n, context) {
var fallback = fallbackLanguage(this.currentLanguage);
var stringTable = this.strings[this.currentLanguage] || this.strings[fallback] || {};
var stringTable = this.strings[this.currentLanguage] || this.strings[baseLanguage()] || {};
var contexts = stringTable[string] || {};
var plurals = contexts[context || noContext] || [];
return plurals[n];
Expand All @@ -103,7 +105,8 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, $h
},

getPlural: function (n, string, stringPlural, scope, context) {
var form = gettextPlurals(this.currentLanguage, n);
var baseLang = baseLanguage();
var form = gettextPlurals(this.currentLanguage !== 'pt_BR' ? baseLang : this.currentLanguage, n);
string = this.getStringForm(string, form, context) || prefixDebug(n === 1 ? string : stringPlural);
if (scope) {
scope.$count = n;
Expand Down

0 comments on commit 3fdb714

Please sign in to comment.