1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Add language support

This commit is contained in:
vrde 2015-07-15 14:52:14 +02:00
parent 3ad7763577
commit 344fffad91
2 changed files with 12 additions and 6 deletions

View File

@ -104,7 +104,7 @@ let AccountSettings = React.createClass({
show={true} show={true}
defaultExpanded={true}> defaultExpanded={true}>
{content} {content}
<Form {/*<Form
url={AppConstants.serverUrl + 'api/users/set_language/'}> url={AppConstants.serverUrl + 'api/users/set_language/'}>
<Property <Property
name='language' name='language'
@ -121,7 +121,7 @@ let AccountSettings = React.createClass({
</select> </select>
</Property> </Property>
<hr /> <hr />
</Form> </Form>*/}
</CollapsibleParagraph> </CollapsibleParagraph>
); );
} }
@ -346,4 +346,4 @@ let APISettings = React.createClass({
} }
}); });
export default SettingsContainer; export default SettingsContainer;

View File

@ -4,6 +4,14 @@ import languages from '../constants/languages';
import { formatText } from './general_utils'; import { formatText } from './general_utils';
export function getLang() {
// this is just for testing, as changing the navigator.language wasn't possible
// return 'fr';
return navigator.languages ? navigator.languages[0] :
(navigator.language || navigator.userLanguage);
}
/** /**
* Is used to translate strings to another language. Basically can be used with C's string format method. * Is used to translate strings to another language. Basically can be used with C's string format method.
* @param {string} s The string you want to translate * @param {string} s The string you want to translate
@ -11,9 +19,7 @@ import { formatText } from './general_utils';
* @return {string} The formated string * @return {string} The formated string
*/ */
export function getLangText(s, ...args) { export function getLangText(s, ...args) {
let lang = navigator.language || navigator.userLanguage; let lang = getLang();
// this is just for testing, as changing the navigator.language wasn't possible
//ang = 'de';
try { try {
if(lang in languages) { if(lang in languages) {
return formatText(languages[lang][s], args); return formatText(languages[lang][s], args);