-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
…des in translations
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
* v0.3.0 | ||
* | ||
* Usage: | ||
* | ||
* | ||
* var translate = require('translate.js') | ||
* | ||
* | ||
* var messages = { | ||
* translationKey: 'translationValue' | ||
* } | ||
|
@@ -38,23 +38,19 @@ | |
return obj && typeof obj === 'object' | ||
} | ||
|
||
function assemble(parts, replacements, count, debug) { | ||
var result = parts[0] | ||
var i = 1 | ||
var len = parts.length | ||
while (i < len) { | ||
var part = parts[i] | ||
var val = replacements[part] | ||
function assemble (parts, replacements, count, debug) { | ||
var result = [].concat(parts) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
StephanHoyer
Author
Owner
|
||
for (var i = 1; i < parts.length; i += 2) { | ||
This comment has been minimized.
Sorry, something went wrong.
maranomynet
Collaborator
|
||
var val = replacements[parts[i]] | ||
if (val == null) { | ||
if (part === 'n' && count != null) { | ||
if (parts[i] === 'n' && count != null) { | ||
This comment has been minimized.
Sorry, something went wrong.
maranomynet
Collaborator
|
||
val = count | ||
} else { | ||
debug && console.warn('No "' + part + '" in placeholder object:', replacements) | ||
val = '{' + part + '}' | ||
debug && console.warn('No "' + parts[i] + '" in placeholder object:', replacements) | ||
val = '{' + parts[i] + '}' | ||
} | ||
} | ||
result += val + parts[i+1] | ||
i += 2 | ||
result[i] = val | ||
} | ||
return result | ||
This comment has been minimized.
Sorry, something went wrong.
maranomynet
Collaborator
|
||
} | ||
|
@@ -105,7 +101,7 @@ | |
return result | ||
} | ||
|
||
var tFunc = function (translationKey, count, replacements) { | ||
function runTranslation (translationKey, count, replacements) { | ||
var translation = tFunc.keys[translationKey] | ||
var complex = count != null || replacements != null | ||
|
||
|
@@ -137,6 +133,14 @@ | |
return translation | ||
} | ||
|
||
var tFunc = function () { | ||
var translation = runTranslation.apply(null, arguments) | ||
if (translation && translation.join) { | ||
return translation.join('') | ||
} | ||
return translation | ||
} | ||
tFunc.v = runTranslation | ||
This comment has been minimized.
Sorry, something went wrong.
maranomynet
Collaborator
|
||
tFunc.keys = messageObject || {} | ||
tFunc.opts = options || {} | ||
|
||
|
This adds overhead to the default case.
Also: Array#concat is supposedly quite a bit slower than Array#slice