i18n #80
|
@ -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;
|
||||
|
|
17
src/i18n.js
|
@ -7,11 +7,12 @@ import RNFS from 'react-native-fs';
|
|||
![]() 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.
|
||||
const isProduction = !__DEV__; // eslint-disable-line no-undef
|
||||
let knownMessages = null;
|
||||
|
||||
window.language = 'en';
|
||||
![]() 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.language = NativeModules.UtilityModule.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 = window.i18n_messages || {};
|
||||
|
||||
function saveMessage(message) {
|
||||
const messagesFilePath = RNFS.ExternalDirectoryPath + '/app-strings.json';
|
||||
![]() do you want this here? do you want this here?
![]() 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
|
||||
![]() 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 messagesFilePath = RNFS.ExternalStorageDirectoryPath + '/lbry-app-strings.json';
|
||||
![]() 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 (knownMessages === null) {
|
||||
RNFS.readFile(messagesFilePath, 'utf8')
|
||||
|
@ -37,7 +38,7 @@ 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.
|
||||
.then(() => {
|
||||
// successful write
|
||||
// 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',
|
||||
() => {
|
||||
|
@ -46,7 +47,7 @@ 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.
|
||||
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.
|
||||
);
|
||||
![]() 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,12 +59,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) {
|
||||
const w = global.window ? global.window : window;
|
||||
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.
|
||||
|
||||
![]() 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'
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
? NativeModules.I18nManager.localeIdentifier
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
: NativeModules.SettingsManager.settings.AppleLocale;
|
||||
![]() 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.language = language ? language.substring(0, 2) : 'en'; */
|
||||
![]() 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 ? w.language : 'en';
|
||||
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
||||
console.log('w.language=' + 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.
|
||||
|
||||
if (!isProduction) {
|
||||
saveMessage(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.
![]() do you want this here? do you want this here?
![]() No, the commented code can be removed. No, the commented code can be removed.
|
|
@ -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 });
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
do you want this here?