Skip to content

Instantly share code, notes, and snippets.

@osdrv
Created August 3, 2011 09:39
Show Gist options
  • Save osdrv/1122264 to your computer and use it in GitHub Desktop.
Save osdrv/1122264 to your computer and use it in GitHub Desktop.
tiny JS i18n support
window.i18n = (() ->
__def_loc = "en_US"
{
locale: (loc) ->
if loc != undefined
__def_loc = loc
else
__def_loc
, bind: (o) ->
if o.i18ze == undefined
o.i18ze = (loc, opts, merge = false) ->
this._i18n_pool = this._i18n_pool || {}
opts = $.merge({}, (this._i18n_pool[loc] || {}), opts) if merge
this._i18n_pool[loc] = opts
if o.i18zed == undefined
o.i18zed = (loc) ->
this._i18n_pool = this._i18n_pool || {}
this._i18n_pool[loc || i18n.locale()]
o
}
)()
@osdrv
Copy link
Author

osdrv commented Aug 3, 2011

i18n.locale("ru_RU")

window.Date.prototype.getMonthName = function() {
  opts = Date.i18zed()
  return opts.month_names[this.getMonth()] if opts != undefined
}

window.i18n.bind(Date).i18ze("ru_RU", { month_names: ["январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "декабрь"]})
d = new Date()
d.getMonthName()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment