i18n #80
16
src/i18n.js
|
@ -36,18 +36,17 @@ function checkMessageAndSave(message, messagesFilePath) {
|
|||
![]() No, the commented code can be removed. No, the commented code can be removed.
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
RNFS.writeFile(messagesFilePath, contents, 'utf8')
|
||||
.then(() => {
|
||||
// successful write
|
||||
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
// send to transifex (should we do this even if the file doesn't get saved?)
|
||||
doTransifexUpload(
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
/* doTransifexUpload(
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
contents,
|
||||
'lbry-mobile',
|
||||
() => {
|
||||
/* successful */
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
// successful
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
},
|
||||
err => {
|
||||
/* failed */
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
// failed
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
}
|
||||
);
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
); */
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
})
|
||||
.catch(err => {
|
||||
if (err) {
|
||||
|
@ -58,7 +57,8 @@ function checkMessageAndSave(message, messagesFilePath) {
|
|||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
}
|
||||
|
||||
export function __(message, tokens) {
|
||||
let language = window.language;
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
const w = global.window ? global.window : window;
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
let language = w.language;
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
|
||||
/* Platform.OS === 'android'
|
||||
? NativeModules.I18nManager.localeIdentifier
|
||||
|
@ -69,9 +69,7 @@ export function __(message, tokens) {
|
|||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
saveMessage(message);
|
||||
}
|
||||
|
||||
const translatedMessage = window.i18n_messages[language]
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
? window.i18n_messages[language][message] || message
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
: message;
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
const translatedMessage = w.i18n_messages[language] ? w.i18n_messages[language][message] || message : message;
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
|
||||
if (!tokens) {
|
||||
return translatedMessage;
|
||||
|
|
|||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
|
@ -51,21 +51,25 @@ class FirstRunScreen extends React.PureComponent {
|
|||
componentDidUpdate() {
|
||||
const { language } = this.props;
|
||||
|
||||
if (language && !this.state.languageLoaded) {
|
||||
if (!this.state.languageLoaded) {
|
||||
this.setState({ languageLoaded: true }, () => {
|
||||
// Load the current language setting before doing anything
|
||||
const languageFile = RNFS.ExternalDirectoryPath + '/' + language + '.json';
|
||||
RNFS.readFile(languageFile, 'utf8')
|
||||
.then(fileContents => {
|
||||
const json = JSON.parse(fileContents);
|
||||
window.language = language;
|
||||
window.i18n_messages[language] = json;
|
||||
this.checkFirstRun();
|
||||
})
|
||||
.catch(err => {
|
||||
// language file doesn't exist? maintain the default language
|
||||
this.checkFirstRun();
|
||||
});
|
||||
if (!language) {
|
||||
this.checkFirstRun();
|
||||
} else {
|
||||
// Load the current language setting before doing anything
|
||||
const languageFile = RNFS.ExternalDirectoryPath + '/' + language + '.json';
|
||||
RNFS.readFile(languageFile, 'utf8')
|
||||
.then(fileContents => {
|
||||
const json = JSON.parse(fileContents);
|
||||
window.language = language;
|
||||
window.i18n_messages[language] = json;
|
||||
this.checkFirstRun();
|
||||
})
|
||||
.catch(err => {
|
||||
// language file doesn't exist? maintain the default language
|
||||
this.checkFirstRun();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
do you want this here?