]> git.gir.st - VimFx.git/blob - extension/lib/translate.coffee
Change license to MIT
[VimFx.git] / extension / lib / translate.coffee
1 # This file provides a simple function for getting the localized version of a
2 # string of text.
3
4 PROPERTIES_FILE = 'vimfx.properties'
5
6 stringBundle = Services.strings.createBundle(
7 # Randomize URI to work around bug 719376.
8 "#{ADDON_PATH}/locale/#{PROPERTIES_FILE}?#{Math.random()}"
9 )
10
11 translate = (name, values...) ->
12 try
13 return stringBundle.formatStringFromName(name, values, values.length)
14 catch error
15 # If you accidentally pass a `name` that does not exist in a '.properties'
16 # file the thrown error is terrible. It only tells you that an error
17 # occurred, but not why. Wrap in a try-catch to fix that.
18 console.error('VimFx: Translation error', name, values, error)
19
20 module.exports = translate
Imprint / Impressum