Skip to content

Commit

Permalink
Merge pull request #9 from mirego/release/0.3.0
Browse files Browse the repository at this point in the history
Bump version - 0.3.0
  • Loading branch information
charlesdemers committed Mar 9, 2015
2 parents 6418624 + c904fce commit deffad4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "foreigner.js",
"version": "0.2.0",
"version": "0.3.0",
"homepage": "https://github.com/mirego/foreigner.js",
"authors": [
"Charles Demers <cdemers@mirego.com>"
Expand Down
32 changes: 19 additions & 13 deletions dist/foreigner.js
@@ -1,4 +1,4 @@
/*! foreigner.js - v0.2.0 - 2015-01-15
/*! foreigner.js - v0.3.0 - 2015-03-09
* http://github.com/mirego/foreigner.js
*
* Copyright (c) 2013-2015 Mirego <http://mirego.com>;
Expand Down Expand Up @@ -27,13 +27,13 @@
"1": "one",
"2": "two"
};
var lookupKey = function(key) {
var string = key.indexOf(".") >= 0 ? lookupKeyPath(key) : lookupSimpleKey(key);
return string ? lookupAlias(string) : null;
var lookupKey = function(key, locale) {
var string = key.indexOf(".") >= 0 ? lookupKeyPath(key, locale) : lookupSimpleKey(key, locale);
return string ? lookupAlias(string, locale) : null;
};
var lookupKeyPath = function(keyPath) {
var lookupKeyPath = function(keyPath, locale) {
var paths = keyPath.split(".");
var value = foreigner.translations[foreigner.locale];
var value = foreigner.translations[locale];
var index = 0;
while (index < paths.length && value) {
var path = paths[index];
Expand All @@ -42,12 +42,12 @@
}
return value;
};
var lookupSimpleKey = function(key) {
return foreigner.translations[foreigner.locale][key];
var lookupSimpleKey = function(key, locale) {
return foreigner.translations[locale][key];
};
var lookupAlias = function(string) {
var lookupAlias = function(string, locale) {
while (typeof string === "string" && string.charAt(0) === "!") {
string = lookupKey(string.slice(1));
string = lookupKey(string.slice(1), locale);
}
return string;
};
Expand Down Expand Up @@ -105,10 +105,16 @@
locale: "",
translations: {},
t: function(key, attrs) {
if (!foreigner.locale) {
throw new Error("[foreigner] You tried to lookup a translation before setting a locale.");
var locale = foreigner.locale;
if (arguments.length === 2 && typeof attrs === "string") {
locale = attrs;
} else if (arguments.length === 3) {
locale = arguments[2];
}
var string = lookupKey(key);
if (!locale) {
throw new Error("[foreigner] You tried to lookup a translation without setting a locale.");
}
var string = lookupKey(key, locale);
if (!string) return null;
if (typeof attrs !== "object") {
return string;
Expand Down
4 changes: 2 additions & 2 deletions dist/foreigner.min.js

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

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "foreigner.js",
"version": "0.2.0",
"version": "0.3.0",
"description": "Foreigner is a JavaScript library that will help you with translations.",
"main": "foreigner.js",
"directories": {
Expand Down

0 comments on commit deffad4

Please sign in to comment.