-
Notifications
You must be signed in to change notification settings - Fork 59
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
Use user-preferred language in labels #578
Conversation
src/constants/label.js
Outdated
["get", "name:latin"], | ||
["get", "name"], | ||
]; | ||
export const localizedName = (function () { |
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.
The text-field
expressions continue to be evaluated statically as the page loads. To dynamically switch languages after the page loads, we could listen for the languagechange
and tear down and rebuild all the layers. This would require refactoring americana.js.
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.
src/constants/label.js
Outdated
let userLocales = | ||
"languages" in navigator ? [...navigator.languages] : [navigator.language]; |
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.
The user-preferred language could be Arabic or Hebrew, which are both written right to left. As tail work, we should install the mapbox-gl-rtl-text plugin to keep the map readable for users of these languages.
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.
How does this work? Is it based on a user's web browser settings? |
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'm not going to pretend that I fully understand how this works, but the result is awesome!
I seem to recall that it was once possible for navigator.languages to be empty, but both chrome and firefox appear to default to en-us when I set their respective preference to empty string, so defensive coding there isn't needed. |
This is actually for Node, which doesn’t support |
Co-authored-by: Josh Lee <jleedev@gmail.com>
Node.js doesn't have |
Oh, right… |
I brought the |
How do we make this change happen? I'm not seeing any place in the main map https://zelonewolf.github.io/openstreetmap-americana to change language |
#622 implemented a control in the lower-right corner to set the map’s language independently of your browser settings, so you no longer need to know the ISO 639 code of the language you want to see. Find out more about Americana’s label localization and its use cases in this OSMUS blog post. |
All map labels now use the
name:*
field corresponding to the user’s preferred language if available, falling back to the user’s second preferred language and so on. If none of the preferred languages is available, labels fall back to the local language. English is no longer hard-coded.Spanish and Traditional Chinese, falling back to the local language:
Working towards #20.