Browse Source

TwigJS function repoTrans() uses sprintf (so you can pass arguments)

master
parent
commit
c9bd98f091
  1. 2
      doc/TwigJS.md
  2. 13
      package-lock.json
  3. 1
      package.json
  4. 5
      src/tagTranslations.js

2
doc/TwigJS.md

@ -58,7 +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 `repoTrans`: translate strings from this repositories' language file (located in `lang/xy.json`, where `xy` stands for the current locale). The string in the language file can include sprintf placeholders (Use the [sprintf-js module](https://www.npmjs.com/package/sprintf-js). Additional parameters to repoTrans will be passed as arguments to the sprintf function.
* 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)`.

13
package-lock.json

@ -1688,6 +1688,13 @@
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"requires": {
"sprintf-js": "~1.0.2"
},
"dependencies": {
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
}
}
},
"array-includes": {
@ -6699,9 +6706,9 @@
"integrity": "sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw=="
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
"integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug=="
},
"standard": {
"version": "16.0.4",

1
package.json

@ -46,6 +46,7 @@
"overpass-layer": "^3.1.0",
"query-string": "^6.13.8",
"sheet-router": "^4.2.3",
"sprintf-js": "^1.1.2",
"weight-sort": "^1.3.1"
},
"scripts": {

5
src/tagTranslations.js

@ -1,5 +1,6 @@
/* global lang_str lang_non_translated */
/* eslint camelcase:0 */
const sprintf = require('sprintf-js')
var OverpassLayer = require('overpass-layer')
var tagLang = null
@ -31,7 +32,9 @@ OverpassLayer.twig.extendFunction('repoTrans', function (str) {
}
let lang = global.currentCategory.repository.lang
return str in lang ? lang[str] : str
const format = str in lang ? lang[str] : str
return vsprintf(format, Array.from(arguments).slice(1))
})
function tagTranslationsIsTranslated (str) {

Loading…
Cancel
Save