1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-13 22:12:50 +02:00

Detect locale

This commit is contained in:
Laurent Cozic
2017-07-25 18:57:06 +00:00
parent e2af824106
commit e128077326
7 changed files with 70 additions and 18 deletions

View File

@@ -11,7 +11,7 @@ import { sprintf } from 'sprintf-js';
import { vorpalUtils } from 'vorpal-utils.js';
import { reg } from 'lib/registry.js';
import { fileExtension } from 'lib/path-utils.js';
import { _, setLocale } from 'lib/locale.js';
import { _, setLocale, defaultLocale, closestSupportedLocale } from 'lib/locale.js';
import os from 'os';
import fs from 'fs-extra';
@@ -318,6 +318,16 @@ class Application {
await Setting.load();
if (Setting.value('firstStart')) {
let locale = process.env.LANG;
if (!locale) locale = defaultLocale();
locale = locale.split('.');
locale = locale[0];
reg.logger().info('First start: detected locale as ' + locale);
Setting.setValue('locale', closestSupportedLocale(locale));
Setting.setValue('firstStart', 0)
}
setLocale(Setting.value('locale'));
this.loadCommands_();

View File

@@ -415,6 +415,9 @@ msgstr ""
msgid "New notebook"
msgstr ""
msgid "There are currently no notes. Create one by clicking on the (+) button."
msgstr ""
msgid "Log"
msgstr ""
@@ -434,6 +437,9 @@ msgstr ""
msgid "The notebook could not be saved: %s"
msgstr ""
msgid "Edit notebook"
msgstr ""
msgid "Untitled"
msgstr ""
@@ -470,10 +476,10 @@ msgstr ""
msgid "Delete notebook"
msgstr ""
msgid "Edit notebook"
msgid "Login with OneDrive"
msgstr ""
msgid "There are currently no notes. Create one by clicking on the (+) button."
msgid "Search"
msgstr ""
msgid ""
@@ -483,3 +489,6 @@ msgstr ""
msgid "You currently have no notebook. Create one by clicking on (+) button."
msgstr ""
msgid "Welcome"
msgstr ""

View File

@@ -450,6 +450,11 @@ msgstr "Nouvelle note"
msgid "New notebook"
msgstr "Nouveau carnet"
msgid "There are currently no notes. Create one by clicking on the (+) button."
msgstr ""
"Ce carnet ne contient aucune note. Créez-en une en cliquant sur le bouton "
"(+)."
msgid "Log"
msgstr "Journal"
@@ -469,6 +474,9 @@ msgstr "Annuler synchronisation"
msgid "The notebook could not be saved: %s"
msgstr "Ce carnet n'a pas pu être sauvegardé : %s"
msgid "Edit notebook"
msgstr "Editer le carnet"
msgid "Untitled"
msgstr "Sans titre"
@@ -505,13 +513,11 @@ msgstr "Supprimer le carnet ?"
msgid "Delete notebook"
msgstr "Supprimer le carnet"
msgid "Edit notebook"
msgstr "Editer le carnet"
msgid "There are currently no notes. Create one by clicking on the (+) button."
msgid "Login with OneDrive"
msgstr ""
msgid "Search"
msgstr ""
"Ce carnet ne contient aucune note. Créez-en une en cliquant sur le bouton "
"(+)."
msgid ""
"Click on the (+) button to create a new note or notebook. Click on the side "
@@ -525,6 +531,9 @@ msgstr ""
"Vous n'avez pour l'instant pas de carnets. Créez-en un en pressant le bouton "
"(+)."
msgid "Welcome"
msgstr ""
#~ msgid ""
#~ "There is currently no notebook. Create one by clicking on the (+) button."
#~ msgstr ""

View File

@@ -415,6 +415,9 @@ msgstr ""
msgid "New notebook"
msgstr ""
msgid "There are currently no notes. Create one by clicking on the (+) button."
msgstr ""
msgid "Log"
msgstr ""
@@ -434,6 +437,9 @@ msgstr ""
msgid "The notebook could not be saved: %s"
msgstr ""
msgid "Edit notebook"
msgstr ""
msgid "Untitled"
msgstr ""
@@ -470,10 +476,10 @@ msgstr ""
msgid "Delete notebook"
msgstr ""
msgid "Edit notebook"
msgid "Login with OneDrive"
msgstr ""
msgid "There are currently no notes. Create one by clicking on the (+) button."
msgid "Search"
msgstr ""
msgid ""
@@ -483,3 +489,6 @@ msgstr ""
msgid "You currently have no notebook. Create one by clicking on (+) button."
msgstr ""
msgid "Welcome"
msgstr ""

View File

@@ -292,4 +292,4 @@ function _(s, ...args) {
return sprintf(result, ...args);
}
export { _, supportedLocales, localeStrings, setLocale, supportedLocalesToLanguages, defaultLocale };
export { _, supportedLocales, localeStrings, setLocale, supportedLocalesToLanguages, defaultLocale, closestSupportedLocale };

View File

@@ -85,6 +85,11 @@ class Setting extends BaseModel {
this.scheduleUpdate();
}
static formatValue(type, value) {
if (type == 'int') return Math.floor(Number(value));
return value;
}
static value(key) {
if (key in this.constants_) {
let output = this.constants_[key];
@@ -94,14 +99,15 @@ class Setting extends BaseModel {
if (!this.cache_) throw new Error('Settings have not been initialized!');
const md = this.settingMetadata(key);
for (let i = 0; i < this.cache_.length; i++) {
if (this.cache_[i].key == key) {
return this.cache_[i].value;
return this.formatValue(md.type, this.cache_[i].value);
}
}
let s = this.settingMetadata(key);
return s.value;
return this.formatValue(md.type, md.value);
}
static isEnum(key) {
@@ -184,6 +190,7 @@ class Setting extends BaseModel {
delete s.appTypes;
delete s.label;
delete s.options;
s.value = this.formatValue(s.type, s.value);
queries.push(Database.insertQuery(this.tableName(), s));
}
@@ -228,6 +235,7 @@ Setting.SYNC_TARGET_ONEDRIVE = 3;
Setting.metadata_ = {
'activeFolderId': { value: '', type: 'string', public: false },
'firstStart': { value: 1, type: 'int', public: false },
'sync.2.path': { value: '', type: 'string', public: true, appTypes: ['cli'] },
'sync.3.auth': { value: '', type: 'string', public: false },
'sync.target': { value: Setting.SYNC_TARGET_ONEDRIVE, type: 'enum', public: true, label: () => _('Synchronisation target'), options: () => {

View File

@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { BackHandler, Keyboard } from 'react-native';
import { BackHandler, Keyboard, NativeModules } from 'react-native';
import { connect, Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux';
import { shimInit } from 'lib/shim-init-react.js';
@@ -31,7 +31,7 @@ import { SideMenu } from 'lib/components/side-menu.js';
import { SideMenuContent } from 'lib/components/side-menu-content.js';
import { DatabaseDriverReactNative } from 'lib/database-driver-react-native';
import { reg } from 'lib/registry.js';
import { _, setLocale } from 'lib/locale.js';
import { _, setLocale, closestSupportedLocale, defaultLocale } from 'lib/locale.js';
import RNFetchBlob from 'react-native-fetch-blob';
import { PoorManIntervals } from 'lib/poor-man-intervals.js';
@@ -400,7 +400,14 @@ async function initialize(dispatch, backButtonHandler) {
reg.logger().info('Database is ready.');
reg.logger().info('Loading settings...');
await Setting.load();
if (Setting.value('firstStart')) {
const locale = NativeModules.I18nManager.localeIdentifier
if (!locale) locale = defaultLocale();
Setting.setValue('locale', closestSupportedLocale(locale));
Setting.setValue('firstStart', 0)
}
setLocale(Setting.value('locale'));
reg.logger().info('Loading folders...');