pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Chatelain <schat...@gmail.com>
Subject Re: Change application locale after startup
Date Fri, 28 Jan 2011 12:16:36 GMT
Ah ok, I see.

I was thinking that maybe there was a more subtle way of doing that.
Something like:

    private Window window = null;
    private BXMLSerializer bxmlSerializer = null;

    public void startup()  {
        Resources resources = new Resources(getClass().getName(),

        bxmlSerializer = new BXMLSerializer();
        window =
    private void setLocale(String lang) {
        Locale.setDefault(new Locale(lang));
        Resources resources = new Resources(getClass().getName(),

In fact the current state of my test application looks like :

public class Main implements Application {

    Window myWindow = new Window();

    public static void main(String[] args) {
        DesktopApplicationContext.main(Main.class, args);

    private void setLanguage(String lang) {
        Locale locale = new Locale(lang);

    private void loadUI() {
        try {
            Resources resources = new Resources(getClass().getName(),
            BXMLSerializer bxmlSerializer = new BXMLSerializer();
            TabPane l_TabPane = (TabPane) bxmlSerializer.readObject(

        } catch (Exception _Ex) {

    public void startup(Display _Display, Map<String, String> _Properties)
            throws Exception {


It works to update localized strings but even if it is easy to reload all
data displayed in the UI by using data binding after reloading the bxml
file, I will loose the state of the UI (split ratio of splitters, selected
tab in a tab pane, etc.).

Anyway, thank you for your answer.


On Thu, Jan 27, 2011 at 4:05 PM, Greg Brown <gk_brown@verizon.net> wrote:

> I need to implement a dynamic localization in my application, meaning the
> user must be able to click on a button in some kind of toolbar and the UI
> must change directly to display all texts in the chosen language without
> restarting the application.
> ...
> So I go back to the localization feature and found on the mailing list the
> question of Joao Neves, and the answer of Greg Brown saying
> >If you define your UI in BXML, you can just reload it after you change the
> locale.
> That seems interesting but I do not understand how to “reload the UI”; if
> someone could post a little code snippet showing how to do that, that would
> be great.
> I don't think there is an example that demonstrates how to do this, but the
> idea is pretty simple. Let's say you have a main Window defined in
> my_window.bxml. Your application loads this window in startup() and stores a
> reference to it. When you want to apply a locale change, you can reload
> my_window.bxml using the Resources loaded from the new locale.
> You might be able to do this by calling shutdown() and startup() on the
> application yourself. I haven't tried it but it might be worth a shot.
> G

View raw message