Skip to content

Commit

Permalink
Added debugLanguage option and set default language=auto
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Aug 1, 2017
1 parent c999724 commit a4bde51
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 326 deletions.
2 changes: 1 addition & 1 deletion ROADMAP.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [x] Restore copy/paste plugin. Move setting onpaste handler to this plugin
- [x] Restore FileBrowser
- [x] Restore Inline toolbar for Image and Table 3.0.1
- [ ] Auto choose language 3.0.2
- [x] Auto choose language. Test language mode. 3.0.2
- [ ] Restore mobile version/Response mode. Switch buttons md - lg - sm 3.0.3
- [ ] Restore Iframe mode 3.0.4
- [ ] Restore themes 3.0.5
Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
Expand Down Expand Up @@ -79,6 +79,7 @@
// url: 'http://localhost:8181/index-test.php'
// }
// },
debugLanguage: true,
buttons: Jodit.defaultOptions.buttons.concat([
{
name: 'insertDate',
Expand Down
20 changes: 17 additions & 3 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,31 @@ export class Config {
direction = '';

/**
* @prop {string} language=en Language by default
* @prop {string} language=auto Language by default. if `auto` language set by document.documentElement.lang || (navigator.language && navigator.language.substr(0, 2)) || (navigator.browserLanguage && navigator.browserLanguage.substr(0, 2)) || 'en'
* @example
* // include in you page lang file
* <script src="jodit/lang/de.js"></script>
* <script>
* vae editor = new Jodit('.editor', {
* var editor = new Jodit('.editor', {
* language: 'de'
* });
* </script>
*/
language = 'en';
language = 'auto';


/**
* @prop {boolean} debugLanguage=false if true all Lang.i18n(key) return `{key}`
* @example
* <script>
* var editor = new Jodit('.editor', {
* debugLanguage: true
* });
*
* console.log(editor.i18n("Test")); // {Test}
* </script>
*/
debugLanguage = false;

/**
* @prop {PlainObject} i18n=Jodit.lang Collection of language pack data {en: {'Type something': 'Type something', ...}}
Expand Down
25 changes: 14 additions & 11 deletions src/Jodit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Selection from './modules/Selection';
import Toolbar from './modules/Toolbar';
import Cookie from './modules/Cookie';
import * as consts from './constants';
import {extend, inArray, dom, each, sprintf, css} from './modules/Helpers';
import {extend, inArray, dom, each, sprintf, css, defaultLanguage} from './modules/Helpers';
import * as helper from './modules/Helpers';
import FileBrowser from "./modules/FileBrowser";
import Uploader from "./modules/Uploader";
Expand All @@ -21,7 +21,7 @@ export default class Jodit extends Component{
static plugins: any = {};
static modules: any = {};
static instances = {};
static lang:any = {};
static lang: any = {};

components: any = [];

Expand Down Expand Up @@ -592,23 +592,26 @@ export default class Jodit extends Component{
* Jodit.defaultOptions.language = 'cs';
* console.log(Jodit.prototype.i18n('Hello world', 'mr.Perkins', 'day')) //Hello mr.Perkins Good day
*/
i18n (key, ...params) {
i18n (key: string, ...params: Array<string|number>) {
if (this.options.debugLanguage) {
return '{' + key + '}';
}

let store,
args = Array.prototype.slice.call(params),
parse = value => sprintf.apply(this, [value].concat(args));
parse = value => sprintf.apply(this, [value].concat(params));

if (this.options !== undefined && Jodit.lang[this.options.language] !== undefined) {
store = Jodit.lang[this.options.language];
if (this.options !== undefined && Jodit.lang[defaultLanguage(this.options.language)] !== undefined) {
store = Jodit.lang[defaultLanguage(this.options.language)];
} else {
if (Jodit.lang[Jodit.defaultOptions.language] !== undefined) {
store = Jodit.lang[Jodit.defaultOptions.language];
if (Jodit.lang[defaultLanguage(Jodit.defaultOptions.language)] !== undefined) {
store = Jodit.lang[defaultLanguage(Jodit.defaultOptions.language)];
} else {
store = Jodit.lang.en;
}
}

if (this.options !== undefined && this.options.i18n[this.options.language] !== undefined && this.options.i18n[this.options.language][key]) {
return parse(this.options.i18n[this.options.language][key]);
if (this.options !== undefined && this.options.i18n[defaultLanguage(this.options.language)] !== undefined && this.options.i18n[defaultLanguage(this.options.language)][key]) {
return parse(this.options.i18n[defaultLanguage(this.options.language)][key]);
}

if (typeof store[key] === 'string' && store[key]) {
Expand Down
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ requireAll(require.context('./styles/modules/', true, /\.less$/));
requireAll(require.context('./styles/widgets/', true, /\.less$/));
requireAll(require.context('./styles/plugins/', true, /\.less$/));

let context = require.context('./styles/icons/', true, /\.svg$/);
const context = require.context('./styles/icons/', true, /\.svg$/);

context.keys().forEach(function (key) {
Toolbar.icons[key.replace('.svg', '').replace('./', '')] = context.apply(this, arguments)
Expand All @@ -35,8 +35,13 @@ context.keys().forEach(function (key) {
.replace(/<!--.*-->/gm, '');
});

let context2 = require.context('./modules/', true, /\.ts/);
const context2 = require.context('./modules/', true, /\.ts/);
context2.keys().forEach(function (key) {
module.exports.modules[key.replace('.ts', '').replace('./', '')] = context2.apply(this, arguments).default;
});
requireAll(require.context('./langs/', true, /\.ts$/));


const context3 = require.context('./langs/', true, /\.ts$/);
context3.keys().forEach(function (key) {
module.exports.lang[key.replace('.ts', '').replace('./', '')] = context3.apply(this, arguments).default;
});
103 changes: 0 additions & 103 deletions src/langs/de.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/langs/de.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Jodit from '../Jodit'
export default Jodit.lang.de = {
export default {
'Type something': 'Schreibe etwas',
// About
'About Jodit': 'Über Jodi',
Expand Down
95 changes: 0 additions & 95 deletions src/langs/en.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/langs/en.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Jodit from '../Jodit'
export default Jodit.lang.en = {
export default {
'Type something': 'Start writing...',
// About
'About Jodit': '',
Expand Down
Loading

0 comments on commit a4bde51

Please sign in to comment.