diff --git a/index.js b/index.js index 9b759e56..69041d60 100644 --- a/index.js +++ b/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)) }) diff --git a/src/tagTranslations.js b/src/tagTranslations.js index 52a0fcb8..81e6dfce 100644 --- a/src/tagTranslations.js +++ b/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