-
-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* i18n API * add readme to locales/locales/
- Loading branch information
1 parent
a030526
commit 36862b0
Showing
13 changed files
with
60 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { locales, DEFAULT_LOCALE } from '../../locales/asJson'; | ||
import { locale } from '../utils/localization'; | ||
|
||
export function getMessage(messageName, substitutions) { | ||
const { message } = ( | ||
locales[locale()] && locales[locale()][messageName] || | ||
DEFAULT_LOCALE[messageName] || | ||
{ message: '' } | ||
); | ||
|
||
// Replace direct references to substitutions, e.g. `First substitution: $1` | ||
// Maximum of 9 substitutions allowed, i.e. only one number after the `$` | ||
return message.replace(/\$(\d)\b(?!\$)/g, (match, number) => substitutions[number - 1] || ''); | ||
|
||
// Chrome also supports named placeholders, e.g. `Error: $error_message$` | ||
// but Transifex does not create the `placeholders` field in exported JSON | ||
// https://developer.chrome.com/extensions/i18n#examples-getMessage | ||
} |
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,6 @@ | ||
import { sendSynchronous } from 'browserEnvironment'; | ||
|
||
export function i18n(messageName, ...substitutions) { | ||
// implementation should return the empty string if it cannot find a translation | ||
return sendSynchronous('i18n', [messageName, substitutions]) || messageName; | ||
} |
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 @@ | ||
require.context('file?name=_locales/[name]/messages.json!./locales', false, /\.json$/); |
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,12 @@ | ||
const localesContext = require.context('json!./locales', false, /\.json$/); | ||
|
||
export DEFAULT_LOCALE from 'json!./locales/en.json'; | ||
|
||
function localeNameFromPath(path) { | ||
return (/\/(\w+)\.json/).exec(path)[1]; | ||
} | ||
|
||
export const locales = localesContext.keys().reduce((obj, key) => { | ||
obj[localeNameFromPath(key)] = localesContext(key); | ||
return obj; | ||
}, {}); |
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,9 @@ | ||
# Localization | ||
|
||
**Do not edit the files in this directory, they are automatically generated.** | ||
|
||
[Instead, visit Transifex if you wish to submit translations.](https://www.transifex.com/reddit-enhancement-suite/reddit-enhancement-suite/) | ||
|
||
## New strings | ||
|
||
New strings should be added to `en.json` and only that file. |
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,2 @@ | ||
{ | ||
} |
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