Created
August 23, 2012 23:22
-
-
Save carlosvillu/3443373 to your computer and use it in GitHub Desktop.
Idea para tener i18n con Require
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Idioma español | |
define (require) -> | |
'Dashboard': 'Panel de control' | |
'Manager': 'Gestor' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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