i18n #80

Merged
akinwale merged 12 commits from i18n into master 2019-12-05 13:16:45 +01:00
5 changed files with 59 additions and 36 deletions
Showing only changes of commit f2ca5fb53e - Show all commits

View file

@ -61,6 +61,7 @@ class FileItemMedia extends React.PureComponent {
let style = this.props.style;
const { duration, isResolvingUri, thumbnail, title, resizeMode } = this.props;
const atStyle = this.state.autoThumbStyle;
if (this.isThumbnailValid(thumbnail) && !this.state.imageLoadFailed) {
if (style == null) {
style = fileItemMediaStyle.thumbnail;

View file

@ -7,11 +7,12 @@ import RNFS from 'react-native-fs';
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
const isProduction = !__DEV__; // eslint-disable-line no-undef
let knownMessages = null;
window.language = 'en';
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
window.language = NativeModules.UtilityModule.language;
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
window.i18n_messages = window.i18n_messages || {};
function saveMessage(message) {
const messagesFilePath = RNFS.ExternalDirectoryPath + '/app-strings.json';
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
// file path that won't get wiped if app storage is cleared or the app is uninstalled
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
const messagesFilePath = RNFS.ExternalStorageDirectoryPath + '/lbry-app-strings.json';
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
if (knownMessages === null) {
RNFS.readFile(messagesFilePath, 'utf8')
@ -37,7 +38,7 @@ function checkMessageAndSave(message, messagesFilePath) {
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
.then(() => {
// successful write
// send to transifex (should we do this even if the file doesn't get saved?)
/* doTransifexUpload(
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
doTransifexUpload(
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
contents,
'lbry-mobile',
() => {
@ -46,7 +47,7 @@ function checkMessageAndSave(message, messagesFilePath) {
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
err => {
// failed
}
); */
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
);
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
})
.catch(err => {
if (err) {
@ -58,12 +59,8 @@ function checkMessageAndSave(message, messagesFilePath) {
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
export function __(message, tokens) {
const w = global.window ? global.window : window;
let language = w.language;
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
/* Platform.OS === 'android'
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
? NativeModules.I18nManager.localeIdentifier
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
: NativeModules.SettingsManager.settings.AppleLocale;
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
window.language = language ? language.substring(0, 2) : 'en'; */
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
let language = w.language ? w.language : 'en';
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
console.log('w.language=' + language + '; message=' + message);
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
if (!isProduction) {
saveMessage(message);

kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.
kauffj commented 2019-12-03 18:26:17 +01:00 (Migrated from github.com)
Review

do you want this here?

do you want this here?
akinwale commented 2019-12-04 08:12:52 +01:00 (Migrated from github.com)
Review

No, the commented code can be removed.

No, the commented code can be removed.

View file

@ -1,5 +1,5 @@
import React from 'react';
import { Lbry } from 'lbry-redux';
import { SETTINGS, Lbry } from 'lbry-redux';
import { ActivityIndicator, Linking, NativeModules, Text, TouchableOpacity, View } from 'react-native';
import { NavigationActions, StackActions } from 'react-navigation';
import AsyncStorage from '@react-native-community/async-storage';
@ -38,6 +38,7 @@ class FirstRunScreen extends React.PureComponent {
walletPassword: '',
syncApplyStarted: false,
syncApplyCompleted: false,
language: null,
};
componentDidMount() {
@ -46,33 +47,51 @@ class FirstRunScreen extends React.PureComponent {
this.setState({ launchUrl: url });
}
});
NativeModules.UtilityModule.getNativeStringSetting(SETTINGS.LANGUAGE, 'en').then(language =>
this.loadLanguage(language)
);
}
componentDidUpdate() {
const { language } = this.props;
if (!this.state.languageLoaded) {
this.setState({ languageLoaded: true }, () => {
if (!language) {
loadLanguage = language => {
if (!language || language === 'en') {
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;
// language exists, so download an update
this.downloadLanguageUpdate(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();
});
}
});
})
.catch(err => {
// language file doesn't exist? maintain the default language
this.checkFirstRun();
});
}
}
};
downloadLanguageUpdate = language => {
fetch('https://lbry.com/i18n/get/lbry-mobile/app-strings/' + language + '.json')
.then(r => r.json())
.then(j => {
window.i18n_messages[language] = j;
// write the language file to the filesystem
const langFilePath = RNFS.ExternalDirectoryPath + '/' + language + '.json';
RNFS.writeFile(langFilePath, JSON.stringify(j), 'utf8');
// update state and client setting
window.language = language;
})
.catch(() => {
/* pass */
});
};
checkFirstRun = () => {
NativeModules.FirstRun.isFirstRun().then(firstRun => {
@ -107,7 +126,7 @@ class FirstRunScreen extends React.PureComponent {
if (this.state.syncApplyStarted && !syncApplyIsPending) {
if (syncApplyErrorMessage && syncApplyErrorMessage.trim().length > 0) {
notify({ message: syncApplyErrorMessage, isError: true });
notify({ message: __(syncApplyErrorMessage), isError: true });
this.setState({ showBottomContainer: true, syncApplyStarted: false, syncApplyCompleted: false });
} else {
this.setState({ syncApplyCompleted: true });

View file

@ -16,7 +16,9 @@ const languageOptions = [
{ code: 'gu', name: __('Gujarati') },
{ code: 'hi', name: __('Hindi') },
{ code: 'id', name: __('Indonesian') },
{ code: 'it', name: __('Italian') },
{ code: 'ms', name: __('Malay') },
{ code: 'tr', name: __('Turkish') },
{ code: 'pl', name: __('Polish') },
{ code: 'pt', name: __('Portuguese') },
{ code: 'es', name: __('Spanish') },
@ -100,6 +102,10 @@ class SettingsPage extends React.PureComponent {
const langFilePath = RNFS.ExternalDirectoryPath + '/' + language + '.json';
RNFS.writeFile(langFilePath, JSON.stringify(j), 'utf8');
// save the setting outside redux because when the first component mounts, the redux value isn't loaded yet
// so we have to load it from native settings
NativeModules.UtilityModule.setNativeStringSetting(SETTINGS.LANGUAGE, value);
// update state and client setting
window.language = language;
setClientSetting(SETTINGS.LANGUAGE, value);

View file

@ -67,7 +67,7 @@ class SyncVerifyPage extends React.PureComponent {
if (this.state.syncApplyStarted && !syncApplyIsPending) {
if (syncApplyErrorMessage && syncApplyErrorMessage.trim().length > 0) {
notify({ message: syncApplyErrorMessage, isError: true });
notify({ message: __(syncApplyErrorMessage), isError: true });
this.setState({ syncApplyStarted: false, autoLoginFlow: false });
} else {
// password successfully verified