Skip to content

Commit

Permalink
Localize query result in API
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 26, 2020
1 parent 39a2611 commit f06587e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
50 changes: 26 additions & 24 deletions api/src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,32 +470,34 @@ class Map {
}
const geometryName = feature.getGeometryName();
const properties = feature.getProperties();
let contentHTML = '';
if (table) {
contentHTML += '<table><tbody>';
for (const key in properties) {
if (!EXCLUDE_PROPERTIES.includes(key) && key !== geometryName && properties[key] !== undefined) {
contentHTML += '<tr>';
contentHTML += `<th>${key}</th>`;
contentHTML += `<td>${properties[key]}</td>`;
contentHTML += '</tr>';
themes.getLocalePromise().then((translations) => {
let contentHTML = '';
if (table) {
contentHTML += '<table><tbody>';
for (const key in properties) {
if (!EXCLUDE_PROPERTIES.includes(key) && key !== geometryName && properties[key] !== undefined) {
contentHTML += '<tr>';
contentHTML += `<th>${translations[key] || key}</th>`;
contentHTML += `<td>${properties[key]}</td>`;
contentHTML += '</tr>';
}
}
contentHTML += '</tbody></table>';
} else {
contentHTML += `<div><b>${properties.title}</b></div>`;
contentHTML += `<p>${properties.description}</p>`;
}
contentHTML += '</tbody></table>';
} else {
contentHTML += `<div><b>${properties.title}</b></div>`;
contentHTML += `<p>${properties.description}</p>`;
}
const element = this.overlay_.getElement();
if (!element) {
throw new Error('Missing element');
}
const content = element.querySelector('.ol-popup-content');
if (!content) {
throw new Error('Missing content');
}
content.innerHTML = contentHTML;
this.overlay_.setPosition(position);
const element = this.overlay_.getElement();
if (!element) {
throw new Error('Missing element');
}
const content = element.querySelector('.ol-popup-content');
if (!content) {
throw new Error('Missing content');
}
content.innerHTML = contentHTML;
this.overlay_.setPosition(position);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/Themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let localePromise;
* @hidden
* @return {Promise<Object<string, string>>} Promise
*/
function getLocalePromise() {
export function getLocalePromise() {
if (!constants.localeUrl) {
// Fallback to an empty dict
return Promise.resolve({});
Expand Down

0 comments on commit f06587e

Please sign in to comment.