Skip to content
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

Add translation process and small fixes #930

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Maputnik is written in typescript and is using [React](https://github.com/facebo

We ensure building and developing Maputnik works with the [current active LTS Node.js version and above](https://github.com/nodejs/Release#release-schedule).

Check out our [Internationalization guide](./src/locales/README.md) for UI text related changes.

### Getting Involved
Join the #maplibre or #maputnik slack channel at OSMUS: get an invite at https://slack.openstreetmap.us/ Read the the below guide in order to get familiar with how we do things around here.

Expand Down
8 changes: 4 additions & 4 deletions src/components/AppToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {

<ToolbarSelect wdKey="nav:inspect">
<MdFindInPage />
<label>{t("View")}
<IconText>{t("View")}
<select
className="maputnik-select"
data-wd-key="maputnik-select"
Expand All @@ -254,12 +254,12 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
})}
</optgroup>
</select>
</label>
</IconText>
</ToolbarSelect>

<ToolbarSelect wdKey="nav:language">
<MdLanguage />
<label>{t("Language")}
<IconText>Language
<select
className="maputnik-select"
data-wd-key="maputnik-lang-select"
Expand All @@ -274,7 +274,7 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
);
})}
</select>
</label>
</IconText>
</ToolbarSelect>

<ToolbarLink href={"https://github.com/maplibre/maputnik/wiki"}>
Expand Down
24 changes: 19 additions & 5 deletions src/components/MapMaplibreGl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import '../libs/maplibre-rtl'
import MaplibreGeocoder, { MaplibreGeocoderApi, MaplibreGeocoderApiConfig } from '@maplibre/maplibre-gl-geocoder';
import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css';
import { withTranslation, WithTranslation } from 'react-i18next'
import i18next from 'i18next'

function renderPopup(popup: JSX.Element, mountNode: ReactDOM.Container): HTMLElement {
ReactDOM.render(popup, mountNode);
Expand Down Expand Up @@ -67,9 +68,11 @@ type MapMaplibreGlInternalProps = {
} & WithTranslation;

type MapMaplibreGlState = {
map: Map | null
inspect: MaplibreInspect | null
zoom?: number
map: Map | null;
inspect: MaplibreInspect | null;
geocoder: MaplibreGeocoder | null;
zoomControl: ZoomControl | null;
zoom?: number;
};

class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, MapMaplibreGlState> {
Expand All @@ -87,7 +90,12 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
this.state = {
map: null,
inspect: null,
geocoder: null,
zoomControl: null,
}
i18next.on('languageChanged', () => {
HarelM marked this conversation as resolved.
Show resolved Hide resolved
this.forceUpdate();
})
}


Expand Down Expand Up @@ -125,6 +133,7 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
this.state.inspect!.render();
}, 500);
}

}

componentDidMount() {
Expand Down Expand Up @@ -152,9 +161,9 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
map.showCollisionBoxes = mapOpts.showCollisionBoxes!;
map.showOverdrawInspector = mapOpts.showOverdrawInspector!;

this.initGeocoder(map);
let geocoder = this.initGeocoder(map);

const zoomControl = new ZoomControl(this.props.t("Zoom:"));
const zoomControl = new ZoomControl();
map.addControl(zoomControl, 'top-right');

const nav = new MapLibreGl.NavigationControl({visualizePitch:true});
Expand Down Expand Up @@ -189,6 +198,8 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
this.setState({
map,
inspect,
geocoder,
zoomControl,
zoom: map.getZoom()
});
})
Expand Down Expand Up @@ -261,10 +272,13 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
maplibregl: MapLibreGl,
});
map.addControl(geocoder, 'top-left');
return geocoder;
}

render() {
const t = this.props.t;
this.state.geocoder?.setPlaceholder(t("Search"));
this.state.zoomControl?.setLabel(t("Zoom:"));
return <div
className="maputnik-map__map"
role="region"
Expand Down
16 changes: 10 additions & 6 deletions src/libs/zoomcontrol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ export default class ZoomControl {
_container: HTMLDivElement | undefined = undefined;
_textEl: HTMLSpanElement | null = null;

constructor(public label: string) {}
constructor() {}

onAdd(map: Map) {
this._map = map;
this._container = document.createElement('div');
this._container.className = 'maplibregl-ctrl maplibregl-ctrl-group maplibregl-ctrl-zoom';
this._container.setAttribute("data-wd-key", "maplibre:ctrl-zoom");
this._container.innerHTML = `
${this.label} <span></span>
`;
this._textEl = this._container.querySelector("span");

this.setLabel("Zoom:");
this.addEventListeners();

return this._container;
Expand All @@ -25,6 +21,14 @@ export default class ZoomControl {
updateZoomLevel() {
this._textEl!.innerHTML = this._map!.getZoom().toFixed(2);
}

setLabel(label: string) {
this._container!.innerHTML = `
${label} <span></span>
`;
this._textEl = this._container!.querySelector("span");
this.updateZoomLevel();
}

addEventListeners (){
this._map!.on('render', () => this.updateZoomLevel());
Expand Down
25 changes: 25 additions & 0 deletions src/locales/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Internationalization

The process of internationlization is pretty straight forward for Maputnik.

In order to add a new translation you'll need to create a new folder and a json file with the relevant language code and make sure all the keys are translated.
The following users can help you with the relevant languages:

- English - @HarelM
- Japanese - @keichan34
- Simplified Chinese - @jieme
- Hebrew - @HarelM
- French - @lhapaipai

If you happen to add a feature which needs some text to be translated, update the translation files.
After running, check your working copy for files and add/correct as needed.

```
npm run i18n:refresh
```

You can test the UI in different languages using the dropdown in the top menu
Note that Maputnik automatically localize based on browser language settings and stores this language in local storage.
You can use incognito mode to check a first time usage.


2 changes: 1 addition & 1 deletion src/styles/_export.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

input.maputnik-string {
margin-left: 5px;
margin: 0 5px;
width: 60%;
display: inline-block;
}
Expand Down
4 changes: 2 additions & 2 deletions src/styles/_filtereditor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

.maputnik-filter-editor-operator {
margin-left: 2%;
margin: 0 2%;
display: inline-block;
width: 17%;

Expand All @@ -30,7 +30,7 @@
.maputnik-filter-editor-args {
display: inline-block;
width: 54%;
margin-left: 2%;
margin: 0 2%;

.maputnik-string,
.maputnik-number {
Expand Down
3 changes: 3 additions & 0 deletions src/styles/_input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@

height: 24px;
}
[dir="rtl"] .maputnik-select {
background: $color-gray url("#{$icon-down-arrow}") left center no-repeat;
}

// MULTIBUTTON
.maputnik-multibutton {
Expand Down
2 changes: 1 addition & 1 deletion src/styles/_layer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
}

&-group-content {
margin-left: $margin-3;
margin: 0 $margin-3;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/styles/_popup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

.maputnik-popup-layer-id {
padding-left: $margin-2;
padding-right: 1.6em;
padding-right: $margin-2;
background-color: $color-midgray;
color: $color-white;
}
Expand All @@ -33,6 +33,7 @@
.maputnik-input-block {
margin: 0;
margin-left: $margin-2;
margin-right: $margin-2;
margin-top: $margin-2;
}
}
Expand All @@ -44,4 +45,5 @@
.maputnik-popup-table-cell {
color: $color-lowgray;
padding-left: $margin-2;
padding-right: $margin-2;
}
8 changes: 4 additions & 4 deletions src/styles/_toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

.maputnik-toolbar-version {
font-size: 10px;
margin-left: 4px;
margin: 0 4px;
white-space: nowrap;
}

Expand All @@ -103,7 +103,7 @@
@extend .maputnik-toolbar-link; /* stylelint-disable-line */

select {
margin-left: 6px;
margin: 0 6px;
border-width: 0;
display: inline;
width: auto;
Expand All @@ -114,12 +114,12 @@
}

.maputnik-icon-text {
padding-left: $margin-1;
padding: 0 $margin-1;
}

.maputnik-icon-action {
display: inline;
margin-left: $margin-1;
margin: 0 $margin-1;
}

.maputnik-toolbar__inner {
Expand Down
3 changes: 1 addition & 2 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@

&:not(:first-child)
{
padding-top: $margin-1;
padding-left: $margin-2;
padding: $margin-1;
}

&:nth-child(1) {
Expand Down
Loading