diff --git a/CliClient/app/app.js b/CliClient/app/app.js index 0fa395d098..558aa38954 100644 --- a/CliClient/app/app.js +++ b/CliClient/app/app.js @@ -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_(); diff --git a/CliClient/locales/en_GB.po b/CliClient/locales/en_GB.po index 3dbbc2e002..d36a6c6a65 100644 --- a/CliClient/locales/en_GB.po +++ b/CliClient/locales/en_GB.po @@ -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 "" diff --git a/CliClient/locales/fr_FR.po b/CliClient/locales/fr_FR.po index 06f120b67d..d9db4b3957 100644 --- a/CliClient/locales/fr_FR.po +++ b/CliClient/locales/fr_FR.po @@ -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 "" diff --git a/CliClient/locales/joplin.pot b/CliClient/locales/joplin.pot index 3dbbc2e002..d36a6c6a65 100644 --- a/CliClient/locales/joplin.pot +++ b/CliClient/locales/joplin.pot @@ -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 "" diff --git a/ReactNativeClient/lib/locale.js b/ReactNativeClient/lib/locale.js index db41483508..f7d0bc71fb 100644 --- a/ReactNativeClient/lib/locale.js +++ b/ReactNativeClient/lib/locale.js @@ -292,4 +292,4 @@ function _(s, ...args) { return sprintf(result, ...args); } -export { _, supportedLocales, localeStrings, setLocale, supportedLocalesToLanguages, defaultLocale }; \ No newline at end of file +export { _, supportedLocales, localeStrings, setLocale, supportedLocalesToLanguages, defaultLocale, closestSupportedLocale }; \ No newline at end of file diff --git a/ReactNativeClient/lib/models/setting.js b/ReactNativeClient/lib/models/setting.js index 95a05d49c8..531c0ec237 100644 --- a/ReactNativeClient/lib/models/setting.js +++ b/ReactNativeClient/lib/models/setting.js @@ -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: () => { diff --git a/ReactNativeClient/root.js b/ReactNativeClient/root.js index 00a39708c3..1e78120427 100644 --- a/ReactNativeClient/root.js +++ b/ReactNativeClient/root.js @@ -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...');