-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localize placeholder based on first language #201
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d8bda5b
localize placeholder based on first language, #150
4e1b2a6
get placeholder is a private method
7ac2a10
fix tests
8ba23ea
update changelog with new changes
5ff3272
merge with version4 working branch
c32841e
merge version4 upstream
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ var exceptions = require('./exceptions'); | |
var MapboxClient = require('@mapbox/mapbox-sdk'); | ||
var mbxGeocoder = require('@mapbox/mapbox-sdk/services/geocoding'); | ||
var MapboxEventManager = require('./events'); | ||
var localization = require('./localization'); | ||
var subtag = require('subtag'); | ||
var geocoderService; | ||
|
||
/** | ||
|
@@ -56,7 +58,6 @@ function MapboxGeocoder(options) { | |
|
||
MapboxGeocoder.prototype = { | ||
options: { | ||
placeholder: 'Search', | ||
zoom: 16, | ||
flyTo: true, | ||
trackProximity: true, | ||
|
@@ -92,7 +93,7 @@ MapboxGeocoder.prototype = { | |
|
||
this._inputEl = document.createElement('input'); | ||
this._inputEl.type = 'text'; | ||
this._inputEl.placeholder = this.options.placeholder; | ||
this._inputEl.placeholder = this._getPlaceholderText(); | ||
|
||
this._inputEl.addEventListener('keydown', this._onKeyDown); | ||
this._inputEl.addEventListener('change', this._onChange); | ||
|
@@ -388,6 +389,27 @@ MapboxGeocoder.prototype = { | |
return this.options.proximity; | ||
}, | ||
|
||
/** | ||
* Get the text to use as the search bar placeholder | ||
* | ||
* If placeholder is provided in options, then use options.placeholder | ||
* Otherwise, if language is provided in options, then use the localized string of the first language if available | ||
* Otherwise use the default | ||
* | ||
* @returns {String} the value to use as the search bar placeholder | ||
* @private | ||
*/ | ||
_getPlaceholderText: function(){ | ||
if (this.options.placeholder) return this.options.placeholder; | ||
if (this.options.language){ | ||
var firstLanguage = this.options.language.split(",")[0]; | ||
var language = subtag.language(firstLanguage); | ||
var localizedValue = localization.placeholder[language]; | ||
if (localizedValue) return localizedValue; | ||
} | ||
return 'Search'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could also lookup 'en' in localization.placeholder, but I don't think it really matters. |
||
}, | ||
|
||
/** | ||
* Subscribe to events that happen within the plugin. | ||
* @param {String} type name of event. Available events and the data passed into their respective event objects are: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Localized values for the placeholder string | ||
* | ||
* @private | ||
*/ | ||
var placeholder = { | ||
// list drawn from https://docs.mapbox.com/api/search/#language-coverage | ||
'de': 'Suche', // german | ||
'it': 'Ricerca', //italian | ||
'en': 'Search', // english | ||
'nl': 'Zoeken', //dutch | ||
'fr': 'Chercher', //french | ||
'ca': 'Cerca', //catalan | ||
'he': 'לחפש', //hebrew | ||
'ja': 'サーチ', //japanese | ||
'lv': 'Meklēt', //latvian | ||
'pt': 'Procurar', //portuguese | ||
'sr': 'Претрага', //serbian | ||
'zh': '搜索', //chinese-simplified | ||
'cs': 'Vyhledávání', //czech | ||
'hu': 'Keresés', //hungarian | ||
'ka': 'ძიება', // georgian | ||
'nb': 'Søke', //norwegian | ||
'sk': 'Vyhľadávanie', //slovak | ||
'th': 'ค้นหา', //thai | ||
'fi': 'Hae',//finnish | ||
'is': 'Leita',//icelandic | ||
'ko': '수색',//korean | ||
'pl': 'Szukaj', //polish | ||
'sl': 'Iskanje' //slovenian | ||
} | ||
|
||
module.exports = {placeholder: placeholder}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a JSDoc
@returns
here for completeness.