2010-04-13 99 views
1

我的應用程序支持國際化和本地化,每個用戶可以選擇他的偏好語言,應用程序將完美地反映它。問題是當第一個用戶選擇英語而第二個用戶選擇法語時,第一個用戶的資源包在刷新他的頁面後將從法語資源讀取。國際化和本地化問題

我使用下面的代碼兩種語言之間切換:

public void changeToEnglish() 
    { 
     FacesContext context = FacesContext.getCurrentInstance(); 
     Locale currentLocale = context.getViewRoot().getLocale(); 
     String locale = "en_US"; 
     Locale newLocale = new Locale(locale); 
     if(!currentLocale.equals(newLocale)) 
      context.getViewRoot().setLocale(newLocale); 
    } 

我有以下我faces_config.xml:

<locale-config> <default-locale>en</default-locale> <supported-locale>fr</supported-locale> </locale-config>

應用反應非常好,以改變語言,但我認爲從FacesContext設置語言環境時,它反映了所有用戶的語言環境。

請幫我這個....

回答

1

給定的代碼不會這樣做。問題出在其他地方或者被誤解了。

但是,更常見的做法是將區域設置存儲在會話範圍的bean中,並使用屬性<f:view>

+0

thx爲您的答覆,實際上我確實保存用戶bean(會話範圍的bean)中的區域設置。我會嘗試在模板中放置,看看會發生什麼。 – Ahmad 2010-04-13 14:36:48

+0

非常感謝BalusC現在工作正常:) – Ahmad 2010-04-13 14:56:05

+0

不客氣。 – BalusC 2010-04-13 14:57:59