Skip to content

Commit

Permalink
Attempt to localize mapbox UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-gokun committed Nov 9, 2019
1 parent da00339 commit d84f4a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/ui/control/fullscreen_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ class FullscreenControl {
}

_updateTitle() {
const title = this._isFullscreen() ? "Exit fullscreen" : "Enter fullscreen";
const title = this._getTitle();
this._fullscreenButton.setAttribute("aria-label", title);
this._fullscreenButton.title = title;
}

_getTitle() {
return this._map._translateUiString(this._isFullscreen() ? "FullscreenControl.ExitTooltip" : "FullscreenControl.EnterTooltip");
}

_isFullscreen() {
return this._fullscreen;
}
Expand Down
8 changes: 8 additions & 0 deletions src/ui/localization/default_locale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @flow

const defaultLocale = {
'FullscreenControl.EnterTooltip': 'Enter fullscreen',
'FullscreenControl.ExitTooltip': 'Exit fullscreen'
};

export default defaultLocale;
12 changes: 10 additions & 2 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type DragPanHandler, {DragPanOptions} from './handler/drag_pan';
import type KeyboardHandler from './handler/keyboard';
import type DoubleClickZoomHandler from './handler/dblclick_zoom';
import type TouchZoomRotateHandler from './handler/touch_zoom_rotate';
import defaultLocale from './localization/default_locale';
import type {TaskID} from '../util/task_queue';
import type {Cancelable} from '../types/cancelable';
import type {
Expand Down Expand Up @@ -96,7 +97,8 @@ type MapOptions = {
renderWorldCopies?: boolean,
maxTileCacheSize?: number,
transformRequest?: RequestTransformFunction,
accessToken: string
accessToken: string,
locale?: Object
};

const defaultMinZoom = 0;
Expand Down Expand Up @@ -235,7 +237,7 @@ const defaultOptions = {
* @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
* @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
* @param {string} [options.accessToken=null] If specified, map will use this token instead of the one defined in mapboxgl.accessToken.
* @param {string} [options.locale=null] A patch to apply to the default localization table. You can replace all UI strings (thereby adding support for a new translation) or just part of them (thereby patching the default translation table).
* @example
* var map = new mapboxgl.Map({
* container: 'map',
Expand Down Expand Up @@ -293,6 +295,7 @@ class Map extends Camera {
_mapId: number;
_localIdeographFontFamily: string;
_requestManager: RequestManager;
_locale: Object;

/**
* The map's {@link ScrollZoomHandler}, which implements zooming in and out with a scroll wheel or trackpad.
Expand Down Expand Up @@ -374,6 +377,7 @@ class Map extends Camera {
this._renderTaskQueue = new TaskQueue();
this._controls = [];
this._mapId = uniqueId();
this._locale = extend({}, defaultLocale, options.locale);

this._requestManager = new RequestManager(options.transformRequest, options.accessToken);

Expand Down Expand Up @@ -1168,6 +1172,10 @@ class Map extends Camera {
}
}

_translateUiString(key: string) {
return this._locale[key] || key;
}

_updateStyle(style: StyleSpecification | string | null, options?: {diff?: boolean} & StyleOptions) {
if (this.style) {
this.style.setEventedParent(null);
Expand Down

0 comments on commit d84f4a4

Please sign in to comment.