Skip to content

Instantly share code, notes, and snippets.

@carlosvillu
Created August 23, 2012 23:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosvillu/3443373 to your computer and use it in GitHub Desktop.
Save carlosvillu/3443373 to your computer and use it in GitHub Desktop.
Idea para tener i18n con Require
class I18n
constructor: (@dicc={}) ->
_: (text) ->
@dicc[text] or text
browserLanguage = navigator.language ||
navigator.userLanguage ||
'en'
define (require) ->
load: (name, req, load) ->
name = browserLanguage unless name isnt ''
req ["locale/#{name.split('_')[0]}/index"], (dicc) ->
load new I18n(dicc)
// Idioma español
define (require) ->
'Dashboard': 'Panel de control'
'Manager': 'Gestor'
# La idea sería algo más o menos así:
# ../locale/i18n.coffee
# ../locale/es/index.coffee
# ../locale/en/index.coffee
# Luego a la hora de usarlo algo así:
define (require) ->
i18n = require("locale/i18n!")
class Main extends Backbone.Router
constructor: (opts) ->
super()
console.log "Create router"
routes:
'': 'dashboard'
'dashboard': 'dashboard'
'manage': 'manage'
dashboard: ->
alert "#{i18n._('Dashboard')}"
manage: ->
alert "#{i18n._('Manage')}"
return Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment