Refactor to ES5 code. Some updates in the docs

This commit is contained in:
jos 2018-02-25 19:54:59 +01:00
parent 6f4729885b
commit 9fb29a644d
5 changed files with 27 additions and 13 deletions

View File

@ -3,8 +3,9 @@
https://github.com/josdejong/jsoneditor
## not yet released, version 5.13.4
## not yet released, version 5.14.0
- Implemented support for translations. Thanks @mariohmol.
- Fixed a bug sometimes occurring when dragging items from array to
object, see #509. Thanks @43081j.
- Fixed autocomplete not accepting returned `null` values, see #512.

View File

@ -194,7 +194,7 @@ Constructs a new JSONEditor.
- `{string} language`
The default language comes from the browser navigator, but you can force a specific language. So use here string as 'en' or 'pt-BR'.
The default language comes from the browser navigator, but you can force a specific language. So use here string as 'en' or 'pt-BR'. Built-in languages: `en`, `pt-BR`. Other translations can be specified via the option `languages`.
- `{Object} languages`
@ -212,6 +212,8 @@ Constructs a new JSONEditor.
}
```
All available fields for translation can be found in the source file `src/js/i18n.js`.
### Methods

View File

@ -2,10 +2,10 @@
<html>
<head>
<title>JSONEditor | Basic usage</title>
<title>JSONEditor | Translate</title>
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
<script src="../dist/jsoneditor.js"></script>
<script src="../dist/jsoneditor.min.js"></script>
<style type="text/css">
#jsoneditor {
@ -16,6 +16,9 @@
</head>
<body>
<p>
JSONEditor has support for multiple languages (i18n), in this case uses <code>pt-BR</code>.
</p>
<p>
<button id="setJSON">Set JSON</button>
<button id="getJSON">Get JSON</button>
@ -28,7 +31,7 @@
var options = {
// switch between pt-BR or en for testing forcing a language
// leave blank to get language
'language': 'en',
'language': 'pt-BR',
'languages': {
'pt-BR': {
'auto': 'Automático testing'

View File

@ -105,7 +105,9 @@ var _defs = {
var _defaultLang = 'en';
var _lang;
var userLang = navigator.language || navigator.userLanguage;
_lang = _locales.find(l => l === userLang);
_lang = _locales.find(function (l) {
return l === userLang;
});
if (!_lang) {
_lang = _defaultLang;
}
@ -115,11 +117,13 @@ module.exports = {
_locales: _locales,
_defs: _defs,
_lang: _lang,
setLanguage(lang) {
setLanguage: function (lang) {
if (!lang) {
return;
}
var langFound = _locales.find(l => l === lang);
var langFound = _locales.find(function (l) {
return l === lang;
});
if (langFound) {
_lang = langFound;
} else {
@ -131,7 +135,9 @@ module.exports = {
return;
}
for (var key in languages) {
var langFound = _locales.find(l => l === key);
var langFound = _locales.find(function (l) {
return l === key;
});
if (!langFound) {
_locales.push(key);
}

View File

@ -10,7 +10,9 @@ var Node = require('./Node');
var ModeSwitcher = require('./ModeSwitcher');
var util = require('./util');
var autocomplete = require('./autocomplete');
var { translate, setLanguages, setLanguage} = require('./i18n');
var translate = require('./i18n').translate;
var setLanguages = require('./i18n').setLanguages;
var setLanguage = require('./i18n').setLanguage;
// create a mixin with the functions for tree mode
var treemode = {};