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 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 - Fixed a bug sometimes occurring when dragging items from array to
object, see #509. Thanks @43081j. object, see #509. Thanks @43081j.
- Fixed autocomplete not accepting returned `null` values, see #512. - Fixed autocomplete not accepting returned `null` values, see #512.

View File

@ -192,12 +192,12 @@ Constructs a new JSONEditor.
Adds status bar to the buttom of the editor - the status bar shows the cursor position and a count of the selected charcters. True by default. Only applicable when `mode` is 'code' or 'text'. Adds status bar to the buttom of the editor - the status bar shows the cursor position and a count of the selected charcters. True by default. Only applicable when `mode` is 'code' or 'text'.
- `{string} language` - `{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` - `{Object} languages`
You can override existing translations or provide a new translation for a specific language. To do it provide an object at languages with language and the keys/values to be inserted. For example: You can override existing translations or provide a new translation for a specific language. To do it provide an object at languages with language and the keys/values to be inserted. For example:
@ -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 ### Methods

View File

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

View File

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

View File

@ -10,7 +10,9 @@ var Node = require('./Node');
var ModeSwitcher = require('./ModeSwitcher'); var ModeSwitcher = require('./ModeSwitcher');
var util = require('./util'); var util = require('./util');
var autocomplete = require('./autocomplete'); 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 // create a mixin with the functions for tree mode
var treemode = {}; var treemode = {};