diff --git a/doc/TwigJS.md b/doc/TwigJS.md index 68eb03c5..ab8526c9 100644 --- a/doc/TwigJS.md +++ b/doc/TwigJS.md @@ -45,6 +45,7 @@ When rendering map features, the following properties are available: * `meta.uid` (UID of the user, who changed the object last) * `map.zoom` (Current zoom level) * `const.*` (Values from the 'const' option) +* `user.*` (Values from the user's options, e.g. `user.ui_lang`, `user.data_lang`, ...) For the info-section of a category the following properties are available: * `layer_id` (the id of the category) @@ -57,6 +58,7 @@ There are several extra functions defined for the TwigJS language: * function `tagTransList`: return the translations of the given tag for tags with multiple values separated by ';' (e.g. 'cuisine'). Parameters: key (required, e.g. 'cuisine'), value (required, e.g. 'kebab' or 'kebab;pizza;noodles;burger'). * function `localizedTag`: return a localized tag if available (e.g. 'name:de' for the german translation of the tag). Parameters: tags (the tags property), key prefix (e.g. 'name'). Which language will be returned depends on the "data language" which can be set via Options. If no localized tag is available, the tag value itself will be returned (e.g. value of 'name'). * function `trans`: return the translation of the given string (e.g. 'save', 'unknown', 'unnamed', ...). Parameters: string (the string to translate). +* function `repoTrans`: translate strings from this repositories' language file (located in `lang/xy.json`, where `xy` stands for the current locale). * function `tagsPrefix(tags, prefix)`: return all tags with the specified prefix. The result will be an array with `{ "en": "name:en", "de": "name:de" }` (for the input `{ "name": "foo", "name:en": "english foo", "name:de": "german foo" }` and the prefix "name:"). * function openingHoursState(opening_hours_definition): returns state of object as string: 'closed', 'open' or 'unknown'. * function colorInterpolate(map, value): interpolates between two or more colors. E.g. `colorInterpolate([ 'red', 'yellow', 'green' ], 0.75)`. @@ -65,6 +67,7 @@ Extra filters: * filter websiteUrl: return a valid http link. Example: `{{ "www.google.com"|websiteUrl }}` -> "http://www.google.com"; `{{ "https://google.com"|websiteUrl }}` -> "https://google.com" * filter `matches`: regular expression match. e.g. `{{ "test"|matches("e(st)$") }}` returns `[ "est", "st" ]`. Returns null if it does not match. * filter `osmDateParse`: returns an array with the lower and upper boundary of the year of a `start_date` tag. See [https://github.com/plepe/openstreetmap-date-parser](openstreetmap-date-parser) for details. +* filter `osmDateFormat`: returns the date as localized strings. Accept an object for options, e.g. `{{ tags.start_date|osmDateFormat({ format: 'short' }) }}`. See [https://github.com/plepe/openstreetmap-date-format](openstreetmap-date-format) for details. * filter `natsort`: Sort an array naturally, see [https://www.npmjs.com/package/natsort](natsort) for details. * filter `unique`: Remove duplicate elements from an array. * filter `md5`: calculate md5 hash of a string. diff --git a/index.php b/index.php index 7a1d6c18..a3c41338 100644 --- a/index.php +++ b/index.php @@ -55,6 +55,7 @@ html_export_var(array( + diff --git a/lang/ast.json b/lang/ast.json index 61b8e5ca..27d9cca2 100644 --- a/lang/ast.json +++ b/lang/ast.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/ca.json b/lang/ca.json index 1338834f..d02858c3 100644 --- a/lang/ca.json +++ b/lang/ca.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/cs.json b/lang/cs.json index 03c56e06..0f5691af 100644 --- a/lang/cs.json +++ b/lang/cs.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/da.json b/lang/da.json index 26db7984..ab48ef81 100644 --- a/lang/da.json +++ b/lang/da.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/de.json b/lang/de.json index 0938b89c..e850b7e5 100644 --- a/lang/de.json +++ b/lang/de.json @@ -15,7 +15,7 @@ "export-prepare": "", "export:GeoJSON": "Als GeoJSON runterladen", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "Einrichtungen", "header:attributes": "Attribute", "header:export": "Export", @@ -30,7 +30,7 @@ "more_results": "", "open": "geöffnet", "options:data_lang": "Datensprache", - "options:data_lang:desc": null, + "options:data_lang:desc": "", "options:data_lang:local": "Lokale Sprache", "options:overpassUrl": "OverpassAPI Adresse", "options:preferredBaseMap": "Bevorzugte Hintergrundkarte", diff --git a/lang/el.json b/lang/el.json index f18a9c35..4e139a0d 100644 --- a/lang/el.json +++ b/lang/el.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/es.json b/lang/es.json index 29574399..defdb6f4 100644 --- a/lang/es.json +++ b/lang/es.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/et.json b/lang/et.json index 007fa41d..864c5004 100644 --- a/lang/et.json +++ b/lang/et.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/hu.json b/lang/hu.json index 2d3c49a6..2ad897aa 100644 --- a/lang/hu.json +++ b/lang/hu.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "Letöltés GeoJSON formátumban", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "Létesítmények", "header:attributes": "Tulajdonságok", "header:export": "Exportálás", diff --git a/lang/it.json b/lang/it.json index 6aa719f2..022b3689 100644 --- a/lang/it.json +++ b/lang/it.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/ja.json b/lang/ja.json index 8a9f09da..fdbed7a0 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/nl.json b/lang/nl.json index bcdfe757..840c7223 100644 --- a/lang/nl.json +++ b/lang/nl.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/pl.json b/lang/pl.json index ed6e7d89..55287109 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -1,46 +1,46 @@ { "available_branches": "", - "back": "", - "categories": "", + "back": "Wstecz", + "categories": "Kategorie", "category-info-tooltip": "", "choose_filter": "", - "closed": "", - "default": "", - "edit": "", - "error": "", + "closed": "Zamknięte", + "default": "Domyślne", + "edit": "Edycja", + "error": "Błąd", "export-all": "", "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", - "header:export": "", + "header:export": "Eksport", "header:osm_meta": "", - "images": "", - "loading": "", + "images": "Obrazy", + "loading": "Wczytywanie", "main:options": "Opcje", "main:permalink": "", - "more": "więcej", + "more": "Więcej", "more_categories": "Więcej kategorii", "more_categories_gitea": "", - "more_results": "", - "open": "", + "more_results": "Więcej wyników", + "open": "Otwórz", "options:data_lang": "Język danych", "options:data_lang:desc": "", "options:data_lang:local": "Język lokalny", "options:overpassUrl": "", "options:preferredBaseMap": "", "options:ui_lang": "Język interfejsu", - "other": "", + "other": "Inne", "repo-use-as-base": "", - "repositories": "", + "repositories": "Repozytoria", "save": "Zapisz", - "show details": "", - "toggle_fullscreen": "", - "unknown": "", - "unnamed": "nienazwane", + "show details": "Pokaż szczegóły", + "toggle_fullscreen": "Przełącz pełny ekran", + "unknown": "Nieznane", + "unnamed": "Nienazwane", "wikipedia:no-url-parse": "", - "zoom_in_appear": "", - "zoom_in_more": "" + "zoom_in_appear": "Powiększ widoczność", + "zoom_in_more": "Powiększ bardziej" } diff --git a/lang/pt-br.json b/lang/pt-br.json index a30e82b9..227f8177 100644 --- a/lang/pt-br.json +++ b/lang/pt-br.json @@ -1,7 +1,7 @@ { - "available_branches": "", + "available_branches": "Redes disponíveis", "back": "voltar", - "categories": "", + "categories": "Categorias", "category-info-tooltip": "Info & Legenda", "choose_filter": "", "closed": "fechado", @@ -23,11 +23,11 @@ "images": "Imagens", "loading": "Carregando...", "main:options": "Opções", - "main:permalink": "", + "main:permalink": "Link permanente", "more": "mais", "more_categories": "Mais categorias", "more_categories_gitea": "Criar & melhorar categorias você mesmo!", - "more_results": "", + "more_results": "Exibir mais resultados", "open": "abrir", "options:data_lang": "Língua dos dados", "options:data_lang:desc": "Muitos elementos do mapa possuem seus nomes (e outras etiquetas) traduzidas para línguas diferentes (p.ex. com 'name:en', 'name:de'). Especificar qual língua deve ser usada para exibição, ou 'Língua local' de forma que sempre os valores não tranduzidos (p.ex. 'name') sejam usados.", @@ -36,8 +36,8 @@ "options:preferredBaseMap": "Mapa-base preferido", "options:ui_lang": "Língua da interface", "other": "Outro", - "repo-use-as-base": "", - "repositories": "", + "repo-use-as-base": "Usar este repositório como repositório base", + "repositories": "Repositórios", "save": "Salvar", "show details": "mostrar detalhes", "toggle_fullscreen": "Alternar modo tela cheia", @@ -45,5 +45,5 @@ "unnamed": "sem nome", "wikipedia:no-url-parse": "Não se pôde analisar URL da Wikipédia", "zoom_in_appear": "aproxime para elementos do mapa aparecer", - "zoom_in_more": "aproxime para mais elementos do mapa" + "zoom_in_more": "aproxime para mais elementos no mapa" } diff --git a/lang/pt.json b/lang/pt.json index 1a9c34b3..20803c68 100644 --- a/lang/pt.json +++ b/lang/pt.json @@ -15,7 +15,7 @@ "export-prepare": "", "export:GeoJSON": "Descarregar como GeoJSON", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "Instalações", "header:attributes": "Atributos", "header:export": "Exportar", diff --git a/lang/ro.json b/lang/ro.json index 054d9abf..8f91ad7a 100644 --- a/lang/ro.json +++ b/lang/ro.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/ru.json b/lang/ru.json index 18f7e1f2..8623600e 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/sr.json b/lang/sr.json index 2311a43c..283571bd 100644 --- a/lang/sr.json +++ b/lang/sr.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/template.json b/lang/template.json index 7f47ea50..6dd14dd4 100644 --- a/lang/template.json +++ b/lang/template.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/lang/uk.json b/lang/uk.json index 1e73f662..85cfce30 100644 --- a/lang/uk.json +++ b/lang/uk.json @@ -12,7 +12,7 @@ "export-prepare": "", "export:GeoJSON": "", "export:OSMJSON": "", - "export:OSMXML": null, + "export:OSMXML": "", "facilities": "", "header:attributes": "", "header:export": "", diff --git a/locales/ast.js b/locales/ast.js new file mode 100644 index 00000000..5a4c4713 --- /dev/null +++ b/locales/ast.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'ast', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +//require('moment/locale/ast') diff --git a/locales/ca.js b/locales/ca.js new file mode 100644 index 00000000..c706ab5e --- /dev/null +++ b/locales/ca.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'ca', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/de') +} + +require('moment/locale/ca') diff --git a/locales/cs.js b/locales/cs.js new file mode 100644 index 00000000..756d0422 --- /dev/null +++ b/locales/cs.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'cs', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/cs') diff --git a/locales/da.js b/locales/da.js new file mode 100644 index 00000000..ebaaae87 --- /dev/null +++ b/locales/da.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'da', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/da') diff --git a/locales/de.js b/locales/de.js new file mode 100644 index 00000000..e0a1f1a4 --- /dev/null +++ b/locales/de.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'de', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/de') +} + +require('moment/locale/de') diff --git a/locales/el.js b/locales/el.js new file mode 100644 index 00000000..11f30501 --- /dev/null +++ b/locales/el.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'el', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/el') diff --git a/locales/en.js b/locales/en.js new file mode 100644 index 00000000..d97b4a4f --- /dev/null +++ b/locales/en.js @@ -0,0 +1,5 @@ +global.locale = { + id: 'en', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} diff --git a/locales/es.js b/locales/es.js new file mode 100644 index 00000000..b0ea3a88 --- /dev/null +++ b/locales/es.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'es', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/es') diff --git a/locales/et.js b/locales/et.js new file mode 100644 index 00000000..e49bd4d2 --- /dev/null +++ b/locales/et.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'et', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/et') diff --git a/locales/fr.js b/locales/fr.js new file mode 100644 index 00000000..de412df6 --- /dev/null +++ b/locales/fr.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'fr', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/fr') diff --git a/locales/hu.js b/locales/hu.js new file mode 100644 index 00000000..72c69419 --- /dev/null +++ b/locales/hu.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'hu', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/hu') diff --git a/locales/it.js b/locales/it.js new file mode 100644 index 00000000..9a10335b --- /dev/null +++ b/locales/it.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'it', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/it') diff --git a/locales/ja.js b/locales/ja.js new file mode 100644 index 00000000..b91a1d1b --- /dev/null +++ b/locales/ja.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'ja', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/ja') diff --git a/locales/nl.js b/locales/nl.js new file mode 100644 index 00000000..dec0f6b8 --- /dev/null +++ b/locales/nl.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'nl', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/nl') diff --git a/locales/pl.js b/locales/pl.js new file mode 100644 index 00000000..53196da7 --- /dev/null +++ b/locales/pl.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'pl', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/pl') diff --git a/locales/pt-br.js b/locales/pt-br.js new file mode 100644 index 00000000..7a227e2b --- /dev/null +++ b/locales/pt-br.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'pt-br', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/pt-br') diff --git a/locales/pt.js b/locales/pt.js new file mode 100644 index 00000000..080dfc8d --- /dev/null +++ b/locales/pt.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'pt', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/pt') diff --git a/locales/ro.js b/locales/ro.js new file mode 100644 index 00000000..2b3c784b --- /dev/null +++ b/locales/ro.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'ro', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/ro') diff --git a/locales/ru.js b/locales/ru.js new file mode 100644 index 00000000..f1ff6add --- /dev/null +++ b/locales/ru.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'ru', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/ru') diff --git a/locales/sr.js b/locales/sr.js new file mode 100644 index 00000000..775fc74e --- /dev/null +++ b/locales/sr.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'sr', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/sr') diff --git a/locales/uk.js b/locales/uk.js new file mode 100644 index 00000000..58e3ae7d --- /dev/null +++ b/locales/uk.js @@ -0,0 +1,7 @@ +global.locale = { + id: 'uk', + moment: require('moment'), + osmDateFormatTemplates: require('openstreetmap-date-format/templates/en') +} + +require('moment/locale/uk') diff --git a/modulekit.php b/modulekit.php index 486465cd..e83f5650 100644 --- a/modulekit.php +++ b/modulekit.php @@ -25,4 +25,4 @@ $include = array( 'style.css', ), ); -$version = "4.3"; +$version = "4.4"; diff --git a/package.json b/package.json index a2e8b41e..257dd35f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openstreetbrowser", - "version": "4.3.2", + "version": "4.4.0", "description": "A re-make of the famous OpenStreetBrowser (pure JS, using Overpass API)", "main": "src/export.js", "repository": "https://github.com/plepe/openstreetbrowser", @@ -34,9 +34,10 @@ "natsort": "^1.0.6", "opening_hours": "^3.5.0", "openstreetbrowser-categories-main": "https://github.com/plepe/openstreetbrowser-categories-main", + "openstreetmap-date-format": "^0.1.0", "openstreetmap-date-parser": "^0.1.0", "openstreetmap-tag-translations": "https://github.com/plepe/openstreetmap-tag-translations", - "overpass-layer": "^2.0.0", + "overpass-layer": "^2.3.0", "query-string": "^5.0.0", "sheet-router": "^4.2.3", "temaki": "^1.0.0", @@ -68,8 +69,9 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "browserify -g browserify-css src/index.js -o dist/tmp1.js && babel --presets env dist/tmp1.js > dist/tmp2.js && mv dist/tmp2.js dist/openstreetbrowser.js && rm dist/tmp1.js", - "watch": "watchify --debug -g browserify-css src/index.js -o dist/openstreetbrowser.js -v", + "build": "npm run build-locales && browserify -g browserify-css src/index.js -o dist/tmp1.js && babel --presets env dist/tmp1.js > dist/tmp2.js && mv dist/tmp2.js dist/openstreetbrowser.js && rm dist/tmp1.js", + "build-locales": "for i in `ls locales/` ; do browserify locales/$i -o dist/locale-$i ; done", + "watch": "npm run build-locales && watchify --debug -g browserify-css src/index.js -o dist/openstreetbrowser.js -v", "prepublish": "npm run build", "lint": "standard src/*.js" }, diff --git a/repo.php b/repo.php index 73c033b9..191ca1fd 100644 --- a/repo.php +++ b/repo.php @@ -35,6 +35,9 @@ if (!isset($_REQUEST['repo'])) { $fullRepoId = $_REQUEST['repo']; list($repoId, $branchId) = explode('~', $fullRepoId); +if (array_key_exists('lang', $_REQUEST)) { + $fullRepoId .= '~' . $_REQUEST['lang']; +} if (!array_key_exists($repoId, $allRepositories)) { Header("HTTP/1.1 404 Repository not found"); @@ -67,7 +70,9 @@ if (isset($config['cache'])) { } } -$data = $repo->data(); +$data = $repo->data($_REQUEST); + +$repo->updateLang($data, $_REQUEST); if (!array_key_exists('index', $data['categories'])) { $data['categories']['index'] = array( diff --git a/src/CategoryOverpass.js b/src/CategoryOverpass.js index 03695e1a..a2ecfc91 100644 --- a/src/CategoryOverpass.js +++ b/src/CategoryOverpass.js @@ -109,6 +109,12 @@ function CategoryOverpass (options, data) { this.layer.on('add', (ob, data) => this.emit('add', ob, data)) this.layer.on('remove', (ob, data) => this.emit('remove', ob, data)) this.layer.on('zoomChange', (ob, data) => this.emit('remove', ob, data)) + this.layer.on('twigData', + (ob, data, result) => { + result.user = global.options + global.currentCategory = this + } + ) call_hooks('category-overpass-init', this) @@ -200,7 +206,7 @@ CategoryOverpass.prototype.updateAssets = function (div) { var src = img.getAttribute('src') || img.getAttribute('data-src') if (src === null) { } else if (src.match(/^(maki|temaki):.*/)) { - let m = src.match(/^(maki|temaki):([a-z0-9-]*)(?:\?(.*))?$/) + let m = src.match(/^(maki|temaki):([a-z0-9-_]*)(?:\?(.*))?$/) if (m) { let span = document.createElement('span') img.parentNode.insertBefore(span, img) diff --git a/src/OpenStreetBrowserLoader.js b/src/OpenStreetBrowserLoader.js index cb47e6ee..660365e7 100644 --- a/src/OpenStreetBrowserLoader.js +++ b/src/OpenStreetBrowserLoader.js @@ -58,6 +58,7 @@ OpenStreetBrowserLoader.prototype.getCategory = function (id, options, callback) this.getCategoryFromData(ids.id, opt, repoData.categories[ids.entityId], function (err, category) { if (category) { category.setMap(this.map) + category.lang = repoData.lang } callback(err, category) @@ -112,6 +113,7 @@ OpenStreetBrowserLoader.prototype.getRepo = function (repo, options, callback) { if (repo) { param.push('repo=' + encodeURIComponent(repo)) } + param.push('lang=' + encodeURIComponent(ui_lang)) param.push(config.categoriesRev) param = param.length ? '?' + param.join('&') : '' diff --git a/src/RepositoryBase.php b/src/RepositoryBase.php index f5f666f5..df0736bf 100644 --- a/src/RepositoryBase.php +++ b/src/RepositoryBase.php @@ -23,16 +23,53 @@ class RepositoryBase { return $ret; } - function data () { + function data ($options) { $data = array( 'categories' => array(), 'templates' => array(), 'timestamp' => Date(DATE_ISO8601, $this->timestamp()), + 'lang' => array(), ); return $data; } + function updateLang (&$data, $options) { + $lang = array_key_exists('lang', $options) ? $options['lang'] : 'en'; + + if (!is_array($data['lang'])) { + $data['lang'] = array(); + } + + foreach ($data['categories'] as $id => $category) { + $name = null; + if (array_key_exists("category:{$id}", $data['lang'])) { + $name = $data['lang']["category:{$id}"]; + + if ($name !== '' && $name !== null) { + $data['categories'][$id]['name'] = array( + $lang => $data['lang']["category:{$id}"], + ); + } + } + elseif (array_key_exists('name', $category)) { + if (array_key_exists($lang, $category['name'])) { + $name = $category['name'][$lang]; + } + elseif (array_key_exists('en', $category['name'])) { + $name = $category['name']['en']; + } + elseif (sizeof($category['name'])) { + $name = $category['name'][array_keys($category['name'])[0]]; + } + + $data['lang']["category:{$id}"] = $name; + + $data['categories'][$id]['name'] = array($lang => $name); + } + } + } + function isCategory ($data) { if (!array_key_exists('type', $data)) { return false; diff --git a/src/RepositoryDir.php b/src/RepositoryDir.php index 37385c7e..ff273cd8 100644 --- a/src/RepositoryDir.php +++ b/src/RepositoryDir.php @@ -14,8 +14,20 @@ class RepositoryDir extends RepositoryBase { return $ts; } - function data () { - $data = parent::data(); + function data ($options) { + $data = parent::data($options); + + $lang = array_key_exists('lang', $options) ? $options['lang'] : 'en'; + + if (file_exists("{$this->path}/lang/{$lang}.json")) { + $data['lang'] = json_decode(file_get_contents("{$this->path}/lang/en.json"), true); + $lang = json_decode(file_get_contents("{$this->path}/lang/{$options['lang']}.json"), true); + foreach ($lang as $k => $v) { + if ($v !== null && $v !== '') { + $data['lang'][$k] = $v; + } + } + } $d = opendir($this->path); while ($f = readdir($d)) { diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php index 503f037c..e7949d7f 100644 --- a/src/RepositoryGit.php +++ b/src/RepositoryGit.php @@ -29,8 +29,20 @@ class RepositoryGit extends RepositoryBase { return $ts; } - function data () { - $data = parent::data(); + function data ($options) { + $data = parent::data($options); + + $lang = array_key_exists('lang', $options) ? $options['lang'] : 'en'; + + if (true) { + $data['lang'] = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:lang/en.json 2>/dev/null"), true); + $lang = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:lang/" . escapeShellArg("{$options['lang']}.json") . " 2>/dev/null"), true); + foreach ($lang as $k => $v) { + if ($v !== null && $v !== '') { + $data['lang'][$k] = $v; + } + } + } $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree {$this->branchEsc}", "r"); while ($r = fgets($d)) { diff --git a/src/category.css b/src/category.css index 3d16f6a5..93ef0d8f 100644 --- a/src/category.css +++ b/src/category.css @@ -152,3 +152,12 @@ .overpass-layer-icon div.sign { font-size: 15px; } +.info .details { + display: none; +} +.info .infoShowDetails .details { + display: initial; +} +.info .infoShowDetails .summary { + display: none; +} diff --git a/src/index.js b/src/index.js index 26d9c093..693e4bdc 100644 --- a/src/index.js +++ b/src/index.js @@ -278,7 +278,7 @@ window.showDetails = function (data, category) { div = document.createElement('div') div.className = 'description' - div.innerHTML = data.data.description || '' + div.innerHTML = data.data.popupDescription || data.data.description || '' dom.appendChild(div) data.sublayer.updateAssets(div, data) diff --git a/src/tagTranslations.js b/src/tagTranslations.js index 706da10d..9f46a828 100644 --- a/src/tagTranslations.js +++ b/src/tagTranslations.js @@ -25,6 +25,10 @@ OverpassLayer.twig.extendFunction('trans', function () { OverpassLayer.twig.extendFunction('isTranslated', function (str) { return tagTranslationsIsTranslated(str) }) +OverpassLayer.twig.extendFunction('repoTrans', function (str) { + let lang = global.currentCategory.lang + return str in lang ? lang[str] : str +}) function tagTranslationsIsTranslated (str) { return !(str in lang_non_translated) && (str in lang_str) diff --git a/src/twigFunctions.js b/src/twigFunctions.js index 8b211a07..1bde15a3 100644 --- a/src/twigFunctions.js +++ b/src/twigFunctions.js @@ -2,6 +2,7 @@ var OverpassLayer = require('overpass-layer') var OpeningHours = require('opening_hours') var colorInterpolate = require('color-interpolate') var osmParseDate = require('openstreetmap-date-parser') +var osmFormatDate = require('openstreetmap-date-format') const natsort = require('natsort') const md5 = require('md5') @@ -66,6 +67,9 @@ OverpassLayer.twig.extendFunction('colorInterpolate', function (map, value) { OverpassLayer.twig.extendFilter('osmParseDate', function (value) { return osmParseDate(value) }) +OverpassLayer.twig.extendFilter('osmFormatDate', function (value, param) { + return osmFormatDate(value, param.length ? param[0] : {}) +}) OverpassLayer.twig.extendFilter('md5', function (value) { if (!(value in md5cache)) { md5cache[value] = md5(value)