From ec1634167d1fd38548ec4a95de8f52238dc05046 Mon Sep 17 00:00:00 2001 From: Sergei Zelinsky Date: Fri, 5 Jan 2018 16:43:27 +0200 Subject: [PATCH 1/2] add local language support --- README.md | 1 + examples/local.html | 34 ++++++++++++++++++++++++++++++++++ index.js | 4 ++-- test/index.test.js | 16 ++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 examples/local.html diff --git a/README.md b/README.md index 688d2ce..5000bab 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ Showcasing the languages supported by Mapbox Streets. - [Spanish](https://mapbox.github.io/mapbox-gl-language/examples/es.html) - [Russian](https://mapbox.github.io/mapbox-gl-language/examples/ru.html) - [Chinese](https://mapbox.github.io/mapbox-gl-language/examples/zh.html) +- [Local language](https://mapbox.github.io/mapbox-gl-language/examples/local.html) ## Supported Styles diff --git a/examples/local.html b/examples/local.html new file mode 100644 index 0000000..20b2ef7 --- /dev/null +++ b/examples/local.html @@ -0,0 +1,34 @@ + + + + + Mapbox GL Language + + + + + + + + +
+ + + + diff --git a/index.js b/index.js index aa416eb..f816f0a 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ function MapboxLanguage(options) { this._defaultLanguage = options.defaultLanguage; this._isLanguageField = options.languageField || /^\{name/; this._getLanguageField = options.getLanguageField || function nameField(language) { - return '{name_' + language + '}'; + return language === 'local' ? '{name}' : '{name_' + language + '}'; }; this._languageSource = options.languageSource || null; this._languageTransform = options.languageTransform || function (style, language) { @@ -32,7 +32,7 @@ function MapboxLanguage(options) { return standardSpacing(style); } }; - this.supportedLanguages = options.supportedLanguages || ['en', 'es', 'fr', 'de', 'ru', 'zh', 'ar', 'pt']; + this.supportedLanguages = options.supportedLanguages || ['local', 'en', 'es', 'fr', 'de', 'ru', 'zh', 'ar', 'pt']; } function standardSpacing(style) { diff --git a/test/index.test.js b/test/index.test.js index 1813887..491661f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -43,7 +43,7 @@ test('setLanguage for different text fields', (assert) => { [6, '{name_es}'] ] } - }, 'switch style to spanish name field'); + }, 'switch style to english name field'); var arStyle = language.setLanguage(style, 'ar'); assert.deepEqual(arStyle.layers[0].layout, { @@ -55,7 +55,19 @@ test('setLanguage for different text fields', (assert) => { [6, '{name_ar}'] ] } - }, 'switch style to spanish arabic field'); + }, 'switch style to arabic name field'); + + var localStyle = language.setLanguage(style, 'local'); + assert.deepEqual(localStyle.layers[0].layout, { + 'text-letter-spacing': 0.15, + 'text-field': { + 'base': 1, + 'stops': [ + [0, '{abbr}'], + [6, '{name}'] + ] + } + }, 'switch style to local name field'); assert.end(); }); From a996bede53f8f824711271901a1415f89de642db Mon Sep 17 00:00:00 2001 From: Sergei Zelinsky Date: Thu, 5 Jul 2018 20:33:21 +0300 Subject: [PATCH 2/2] use 'mul' instead of 'local' to support the local language --- README.md | 2 +- examples/{local.html => multilingual.html} | 2 +- index.js | 4 ++-- test/index.test.js | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) rename examples/{local.html => multilingual.html} (97%) diff --git a/README.md b/README.md index 0b5c96e..5b3a5cf 100644 --- a/README.md +++ b/README.md @@ -108,9 +108,9 @@ Showcasing the languages supported by Mapbox Streets. - [English](https://mapbox.github.io/mapbox-gl-language/examples/en.html) - [French](https://mapbox.github.io/mapbox-gl-language/examples/fr.html) - [German](https://mapbox.github.io/mapbox-gl-language/examples/de.html) -- [Local language](https://mapbox.github.io/mapbox-gl-language/examples/local.html) - [Japanese](https://mapbox.github.io/mapbox-gl-language/examples/ja.html) - [Korean](https://mapbox.github.io/mapbox-gl-language/examples/ko.html) +- [Multilingual](https://mapbox.github.io/mapbox-gl-language/examples/multilingual.html) - [Portuguese](https://mapbox.github.io/mapbox-gl-language/examples/pt.html) - [Russian](https://mapbox.github.io/mapbox-gl-language/examples/ru.html) - [Spanish](https://mapbox.github.io/mapbox-gl-language/examples/es.html) diff --git a/examples/local.html b/examples/multilingual.html similarity index 97% rename from examples/local.html rename to examples/multilingual.html index 20b2ef7..1fad1af 100644 --- a/examples/local.html +++ b/examples/multilingual.html @@ -26,7 +26,7 @@ }); mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.1.0/mapbox-gl-rtl-text.js'); map.addControl(new MapboxLanguage({ - defaultLanguage: 'local' + defaultLanguage: 'mul' })); diff --git a/index.js b/index.js index ec480f4..bda7206 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ function MapboxLanguage(options) { this._defaultLanguage = options.defaultLanguage; this._isLanguageField = options.languageField || /^\{name/; this._getLanguageField = options.getLanguageField || function nameField(language) { - return language === 'local' ? '{name}' : '{name_' + language + '}'; + return language === 'mul' ? '{name}' : '{name_' + language + '}'; }; this._languageSource = options.languageSource || null; this._languageTransform = options.languageTransform || function (style, language) { @@ -34,7 +34,7 @@ function MapboxLanguage(options) { } }; this._excludedLayerIds = options.excludedLayerIds || []; - this.supportedLanguages = options.supportedLanguages || ['ar', 'en', 'es', 'fr', 'de', 'local', 'ja', 'ko', 'pt', 'ru', 'zh']; + this.supportedLanguages = options.supportedLanguages || ['ar', 'en', 'es', 'fr', 'de', 'ja', 'ko', 'mul', 'pt', 'ru', 'zh']; } function standardSpacing(style) { diff --git a/test/index.test.js b/test/index.test.js index 6c9cfa0..133834e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -55,8 +55,8 @@ test('setLanguage for different text fields', (assert) => { } }, 'switch style to arabic name field'); - var localStyle = language.setLanguage(style, 'local'); - assert.deepEqual(localStyle.layers[0].layout, { + var mulStyle = language.setLanguage(style, 'mul'); + assert.deepEqual(mulStyle.layers[0].layout, { 'text-letter-spacing': 0.15, 'text-field': { 'base': 1, @@ -65,7 +65,7 @@ test('setLanguage for different text fields', (assert) => { [6, '{name}'] ] } - }, 'switch style to local name field'); + }, 'switch style to multilingual name field'); assert.end(); });