-
-
Save grEvenX/1901271 to your computer and use it in GitHub Desktop.
localization discussion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var completeString = _('I am {role} and {nationality}', 'domain', { | |
role: 'monkey', | |
nationality: 'norwegian' | |
}); | |
var featureList = '<ul>' + _('#info', 'domain').join('</li><li>') + '</li>'; | |
function _(string, domain, values) { | |
var processedValues = {}; | |
for (var key in values) { | |
var value = values[key]; | |
// var translatedValues = _(value, domain); | |
var translatedValues = _(key, domain); | |
if (typeof(translatedValues[value] == 'undefined')) { | |
// don't have a translation, return the value instead... | |
processedValues[key] = value; | |
// TODO; error log warning 'whooopa, forgot to translate something there or invalid key!'; | |
} | |
// found it, keep the value | |
var translatedValue = translatedValues[value]; | |
processedValues[key] = translatedValue; | |
string.replace(/['{', key, '}'].join('')/, processedValues[key]); | |
} | |
return string; | |
// _validate('I am {role} and {nationality}', 'domain', 'role', role); | |
} | |
Translation file: | |
'current_strength' : 'Current password strength', | |
'#info' : [ | |
'localized line #1', | |
'localized line #2' | |
], | |
'I am {#phoneno} and {nationality}': 'Jeg er {phoneno} og {nationality}', | |
'I am {role} and {nationality:common}': 'Jeg er {role} og {nationality}', | |
'role' : { | |
'administrator': 'administrator', | |
'developer': 'utvikler' | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment