1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: WYSIWYG: Fixed UI translation issue for certain languages

This commit is contained in:
Laurent Cozic 2020-05-11 18:59:23 +01:00
parent fa76c5db8d
commit dacf6377ae
5 changed files with 21 additions and 4 deletions

View File

@ -34,6 +34,7 @@ ElectronClient/lib/vendor/sjcl.js
ElectronClient/locales
ElectronClient/node_modules
ElectronClient/packageInfo.js
ElectronClient/gui/NoteEditor/NoteBody/TinyMCE/supportedLocales.js
highlight.pack.js
Modules/TinyMCE/JoplinLists/
node_modules/

1
.gitignore vendored
View File

@ -42,6 +42,7 @@ ReactNativeClient/lib/csstojs/
ReactNativeClient/lib/rnInjectedJs/
ElectronClient/gui/note-viewer/fonts/
ElectronClient/gui/note-viewer/lib.js
ElectronClient/gui/NoteEditor/NoteBody/TinyMCE/supportedLocales.js
Clipper-source/
Clipper/joplin-webclipper-source.zip
joplin-webclipper-source.zip

View File

@ -7,11 +7,12 @@ import { menuItems, ContextMenuOptions, ContextMenuItemType } from '../../utils/
const { MarkupToHtml } = require('lib/joplin-renderer');
const taboverride = require('taboverride');
const { reg } = require('lib/registry.js');
const { _ } = require('lib/locale');
const { _, closestSupportedLocale } = require('lib/locale');
const BaseItem = require('lib/models/BaseItem');
const Resource = require('lib/models/Resource');
const { themeStyle, buildStyle } = require('../../../../theme.js');
const { clipboard } = require('electron');
const supportedLocales = require('./supportedLocales');
function markupRenderOptions(override:any = null) {
return {
@ -473,6 +474,8 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
const contextMenuItemNames = [];
for (const name in contextMenuItems) contextMenuItemNames.push(contextMenuItemNameWithNamespace(name));
const language = closestSupportedLocale(props.locale, true, supportedLocales);
const editors = await (window as any).tinymce.init({
selector: `#${rootIdRef.current}`,
width: '100%',
@ -489,7 +492,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => {
branding: false,
target_list: false,
table_resize_bars: false,
language: props.locale,
language: ['en_US', 'en_GB'].includes(language) ? undefined : language,
toolbar: 'bold italic | link joplinInlineCode joplinCodeBlock joplinAttach | numlist bullist joplinChecklist | h1 h2 h3 hr blockquote table joplinInsertDateTime',
localization_function: _,
contextmenu: contextMenuItemNames.join(' '),

View File

@ -1,4 +1,5 @@
const fs = require('fs-extra');
const glob = require('glob');
async function main() {
const sourceDir = `${__dirname}/../../Modules/TinyMCE/langs`;
@ -7,6 +8,17 @@ async function main() {
await fs.remove(destDir);
await fs.mkdirp(destDir);
await fs.copy(sourceDir, destDir);
const supportedLocales = glob.sync(`${sourceDir}/*.js`).map(s => {
s = s.split('/');
s = s[s.length - 1];
s = s.split('.');
return s[0];
});
const content = `module.exports = ${JSON.stringify(supportedLocales, null, 2)}`;
await fs.writeFile(`${__dirname}/../gui/NoteEditor/NoteBody/TinyMCE/supportedLocales.js`, content, 'utf8');
}
module.exports = main;

View File

@ -225,8 +225,8 @@ function supportedLocalesToLanguages(options = null) {
return output;
}
function closestSupportedLocale(canonicalName, defaultToEnglish = true) {
const locales = supportedLocales();
function closestSupportedLocale(canonicalName, defaultToEnglish = true, locales = null) {
locales = locales === null ? supportedLocales() : locales;
if (locales.indexOf(canonicalName) >= 0) return canonicalName;
const requiredLanguage = languageCodeOnly(canonicalName).toLowerCase();