From e4fb6c1feee3b07bd29758a213d51b7ef60400f4 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Tue, 11 Dec 2012 10:48:19 +0900 Subject: [PATCH] Completed dynamic I18n intetegration. travis-web starts in English. When the user logs in, it switches to their locale, when they logout, it goes back to english. --- assets/scripts/app/auth.coffee | 2 ++ assets/scripts/app/models/user.coffee | 7 +++---- assets/scripts/app/views/application.coffee | 7 ------- assets/scripts/travis.coffee | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/assets/scripts/app/auth.coffee b/assets/scripts/app/auth.coffee index 6d23cb4c..3fc495ba 100644 --- a/assets/scripts/app/auth.coffee +++ b/assets/scripts/app/auth.coffee @@ -41,6 +41,7 @@ Travis.storage.removeItem('travis.user') Travis.storage.removeItem('travis.token') Travis.sessionStorage.clear() + Travis.setLocale Travis.default_locale @setData() trySignIn: -> @@ -65,6 +66,7 @@ @afterSignIn(data.user) if data?.user afterSignIn: (user) -> + Travis.setLocale user.locale || Travis.default_locale Travis.trigger('user:signed_in', user) @get('app.router').send('afterSignIn', @readAfterSignInPath()) diff --git a/assets/scripts/app/models/user.coffee b/assets/scripts/app/models/user.coffee index 7308707b..f9bb05d4 100644 --- a/assets/scripts/app/models/user.coffee +++ b/assets/scripts/app/models/user.coffee @@ -19,7 +19,7 @@ require 'travis/model' Ember.run.next this, -> transaction = @get('store').transaction() transaction.add this - + urlGithub: (-> "https://github.com/#{@get('login')}" ).property() @@ -32,9 +32,7 @@ require 'travis/model' ).property() updateLocale: (locale) -> - Travis.updateLocale(locale) - @setWithSession('locale', locale) - + transaction = @get('transaction') transaction.commit() @@ -46,6 +44,7 @@ require 'travis/model' transaction.add self @addObserver 'isSaving', observer + Travis.setLocale(locale) type: (-> 'user' diff --git a/assets/scripts/app/views/application.coffee b/assets/scripts/app/views/application.coffee index 48403270..f738ccb4 100644 --- a/assets/scripts/app/views/application.coffee +++ b/assets/scripts/app/views/application.coffee @@ -12,13 +12,6 @@ # popup: (event) -> # console.log event - localeDidChange: (-> - if locale = Travis.app.get('auth.user.locale') - if Travis.needsLocaleChange(locale) - Travis.setLocale(locale) - Travis.app.get('router').reload() - ).observes('Travis.app.auth.user.locale') - click: (event) -> # TODO: this solves the case of closing menus and popups, # but I would like to rewrite it later, not sure how diff --git a/assets/scripts/travis.coffee b/assets/scripts/travis.coffee index 9f244785..16ffbe55 100644 --- a/assets/scripts/travis.coffee +++ b/assets/scripts/travis.coffee @@ -75,7 +75,7 @@ Storage = Em.Object.extend storage )() - + default_locale: 'en' sessionStorage: (-> storage = null try @@ -93,7 +93,7 @@ Storage = Em.Object.extend location.href = location.href.replace('#!/', '') if location.hash.slice(0, 2) == '#!' I18n.fallbacks = true - Travis.set 'locale', 'en' + Travis.setLocale 'locale', @defualt_locale Ember.run.next this, -> app = Travis.App.create(attrs || {})