Browse Source

tagTranslations: improve parameter handling

master
parent
commit
d8879bb96c
  1. 1
      index.js
  2. 16
      src/tagTranslations.js

1
index.js

@ -47,6 +47,7 @@ window.onload = function() {
}
console.log(tagTranslations.trans('amenity'))
console.log(tagTranslations.trans('amenity', undefined))
console.log(tagTranslations.trans('amenity', 'restaurant'))
console.log(tagTranslations.trans('amenity', 'restaurant', 5))
})

16
src/tagTranslations.js

@ -1,8 +1,8 @@
var OverpassLayer = require('overpass-layer')
var translations = null
OverpassLayer.twig.extendFunction('tagTrans', function (key, value, count) {
return tagTranslationsTrans(key, value, count)
OverpassLayer.twig.extendFunction('tagTrans', function () {
return tagTranslationsTrans.apply(this, arguments)
})
function tagTranslationsLoad (path, lang, callback) {
@ -27,10 +27,20 @@ function tagTranslationsLoad (path, lang, callback) {
req.send()
}
function tagTranslationsTrans (tag, value, count) {
function tagTranslationsTrans () {
var ret = null
var fallback = null
tag = arguments[0]
value = undefined
count = undefined
if (arguments.length > 1) {
value = typeof arguments[1] === 'undefined' ? null : arguments[1]
}
if (arguments.length > 2) {
count = arguments[2]
}
if (typeof value === 'undefined') {
fallback = tag

Loading…
Cancel
Save