Skip to content

Commit

Permalink
Add builds
Browse files Browse the repository at this point in the history
  • Loading branch information
musterknabe committed Jun 16, 2015
1 parent 986423b commit 4aabe07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions build/translate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Microlib for translations with support for placeholders and multiple plural forms.
*
* v1.0.1
* v1.1.0
*
* Usage:
* var messages = {
Expand All @@ -12,8 +12,9 @@
* }
*
* var options = {
* debug: true, //[Boolean]: Logs missing translations to console and adds @@-markers around output. Defaults to false.
* namespaceSplitter: '::' //[String|RegExp]: You can customize the part which splits namespace and translationKeys. Defaults to '::'.
* // These are the defaults:
* debug: false, //[Boolean]: Logs missing translations to console and adds @@-markers around output.
* namespaceSplitter: '::' //[String|RegExp]: You can customize the part which splits namespace and translationKeys.
* }
*
* var t = libTranslate.getTranslationFunction(messages, [options])
Expand Down Expand Up @@ -63,13 +64,24 @@

function getPluralValue(translation, count) {
if (isObject(translation)) {
if(Object.keys(translation).length === 0) {
var keys = Object.keys(translation);
var upperCap;

if(keys.length === 0) {
debug && console.log('[Translation] No plural forms found.');
return null;
}

for(var i = 0; i < keys.length; i++) {
if(keys[i].indexOf('gt') === 0) {
upperCap = parseInt(keys[i].replace('gt', ''), 10);
}
}

if(translation[count]){
translation = translation[count];
} else if(count > upperCap) { //int > undefined returns false
translation = translation['gt' + upperCap];
} else if(translation.n) {
translation = translation.n;
} else {
Expand Down
4 changes: 2 additions & 2 deletions build/translate.min.js

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

0 comments on commit 4aabe07

Please sign in to comment.