Skip to content

Commit

Permalink
test locale overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed May 23, 2022
1 parent b3cebc2 commit c5172df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
5 changes: 0 additions & 5 deletions debug/locale.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
'NavigationControl.ResetBearing': 'X Reset bearing to north',
'NavigationControl.ZoomIn': 'X Zoom in',
'NavigationControl.ZoomOut': 'X Zoom out',
'ScaleControl.Feet': 'X ft',
'ScaleControl.Meters': 'X m',
'ScaleControl.Kilometers': 'X km',
'ScaleControl.Miles': 'X mi',
'ScaleControl.NauticalMiles': 'X nm',
'ScrollZoomBlocker.CtrlMessage': 'X Use ctrl + scroll to zoom the map',
'ScrollZoomBlocker.CmdMessage': 'X Use ⌘ + scroll to zoom the map',
'TouchPanBlocker.Message': 'X Use two fingers to move the map'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ui/control/fullscreen.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('FullscreenControl makes optional container element full screen', (t) => {
t.end();
});

test('FullscreenControl changes language after map.setLanguage', (t) => {
test('FullscreenControl changes language after setLanguage', (t) => {
const selector = '.mapboxgl-ctrl-fullscreen';

const map = createMap(t);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ui/control/scale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('ScaleControl should change unit of distance after calling setUnit', (t) =>
t.end();
});

test('ScaleControl changes language after map.setLanguage', (t) => {
test('ScaleControl changes language after setLanguage', (t) => {
const map = createMap(t);
const scale = new ScaleControl();
const selector = '.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-scale';
Expand Down
34 changes: 34 additions & 0 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import simulate from '../../util/simulate_interaction.js';
import {fixedLngLat, fixedNum} from '../../util/fixed.js';
import Fog from '../../../src/style/fog.js';
import Color from '../../../src/style-spec/util/color.js';
import getUIString from '../../../src/ui/get_ui_string.js';
import {MAX_MERCATOR_LATITUDE} from '../../../src/geo/mercator_coordinate.js';

function createStyleSource() {
Expand Down Expand Up @@ -2372,6 +2373,39 @@ test('Map', (t) => {
t.end();
});
});

t.test('English is the default UI language', (t) => {
const map = createMap(t);
map.on('style.load', () => {
t.equal(map._getUIString('Map.Title'), getUIString('en', 'Map.Title'));
t.end();
});
});

t.test('can change UI language', (t) => {
const map = createMap(t);
map.on('style.load', () => {
t.equal(map._getUIString('Map.Title'), getUIString('en', 'Map.Title'));
map.setLanguage('es');
t.equal(map._getUIString('Map.Title'), getUIString('es', 'Map.Title'));
t.end();
});
});

t.test('can override UI language with `locale` property', (t) => {
const locale = {
'Map.Title': 'X Map',
};

const map = createMap(t, {locale});
map.on('style.load', () => {
t.equal(map._getUIString('Map.Title'), locale['Map.Title']);
map.setLanguage('es');
t.equal(map._getUIString('Map.Title'), locale['Map.Title'], 'if the locale is overridden, changing map language should not affect UI');
t.end();
});
});

t.end();
});

Expand Down

0 comments on commit c5172df

Please sign in to comment.