-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated all code to use new localicious I18n
- Loading branch information
Showing
125 changed files
with
7,935 additions
and
164 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
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
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
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
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
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,42 @@ | ||
import en from "./js/en/strings.json"; | ||
import nl from "./js/nl/strings.json"; | ||
import {reportError} from "../api"; | ||
|
||
const translations = { | ||
en: en, | ||
nl: nl, | ||
}; | ||
|
||
const format = (msg, ...args) => { | ||
let result = msg; | ||
for (let i = 0; i < args.length; i++) { | ||
const pos = i + 1; | ||
if (typeof args[i] === "string") { | ||
result = result.replace("%" + pos + "$s", args[i]); | ||
} | ||
if (typeof args[i] === "number") { | ||
result = result.replace("%" + pos + "$d", args[i]); | ||
} | ||
} | ||
return result; | ||
}; | ||
|
||
let locale = "en" | ||
|
||
const I18n = { | ||
changeLocale: lang => locale = lang, | ||
currentLocale: () => locale, | ||
t: (key, model = {}, fallback = null) => { | ||
const msg = translations[locale][key] | ||
if (!msg) { | ||
if (fallback) { | ||
return fallback; | ||
} | ||
reportError({"Missing translation": `${key} in ${locale} translation`}); | ||
return `[missing "${key}" translation]`; | ||
} | ||
return format(msg, ...Object.values(model)); | ||
} | ||
}; | ||
|
||
export default I18n; |
Oops, something went wrong.