-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aafbb16
commit eaed8d5
Showing
2 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* i18n support initialisation function | ||
* | ||
* @constructor | ||
* @param {Object} translations - Key-value pairs of the translation | ||
strings to use. | ||
*/ | ||
function I18n (translations) { | ||
console.log(this) | ||
|
||
// List of translations | ||
this.translations = translations || {} | ||
} | ||
|
||
/** | ||
* The most used function - takes the key for a given piece of UI text and | ||
* returns the appropriate string. | ||
* | ||
* @param {String} lookupKey - The lookup key of the string to use. | ||
* @returns {String} - The appropriate translation string. | ||
*/ | ||
I18n.prototype.t = function (lookupKey) { | ||
var outputString = lookupKey | ||
|
||
// Error if no lookup key has been provided | ||
// Otherwise assign the string to our processing variable | ||
if (!lookupKey) { | ||
if ('console' in window) { | ||
console.log(new Error('i18n lookup key missing.')) | ||
} | ||
return | ||
} else { | ||
outputString = this.translations[lookupKey] | ||
} | ||
|
||
return outputString | ||
} | ||
|
||
export default I18n |