about how translate gluon Desktop Programm

159 views Asked by At

Aloha guy's,

  1. can you explain the file for what this can be good?? in project explorer -> Gradle: org.controlsfx:controlsfx:8.40.12 -> Resource Bundel 'controlsfx' -> here the different file in different language. Can i with this translate my Programm content englisch,Germany,Polish and can i make it editable

    2.if the first one was a stupid idee how i can translate it? my idee is make translate properties lake this english.properties, germany.properties, polish.properties save in resources with loade with this

        stateManager.setPersistenceMode(StateManager.PersistenceMode.USER);
    

    try { input = new FileInputStream( stateManager.getProperty("Languge").orElse("").toString().trim()+".properties");// load a properties file prop.load(input);

        // get the property value and print it out
        System.out.println(prop.getProperty("database"));
        System.out.println(prop.getProperty("dbuser"));
        System.out.println(prop.getProperty("dbpassword"));
    
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
2

There are 2 answers

0
José Pereda On

If you create a Desktop project with the Gluon plugin for your IDE, using for instance the Multi View Project template, you will notice that each view has a properties file.

This default properties file contains key-values in English. But you can easily create a copy of that file, rename it with a different locale, and using the same keys, provide values in that locale.

For instance, for primary.properties

label.text=Welcome
button.text=Go to Secondary View

you can create primary_es.properties in the same package, with:

label.text=Bienvenido
button.text=Ir a Vista Secundaria

Once you have several locales for a given properties file, your IDE will show all at once:

netbeans locale

And this is it, you don't need to change anything in your code. The default locale will be used to select the correct properties file.

Obviously, you can select a different locale in runtime. For that you will have to use a different resource bundle:

@Override
public void init() {
     // other Locale different than the default:
    resourceBundle = ResourceBundle.getBundle(
          "<your.views.package>.primary",
          Locale.ENGLISH);
    ...
}
1
Harry05 On

@José Pereda

do you mine samthing like this for properties? image where i save Properties

I do also this in my WelcomeController

public void initialize() {
    String language;
    Locale currentLocale;
    language = new String("pl");
    currentLocale = new Locale(language);
    ResourceBundle resourceBundle = ResourceBundle.getBundle("bundles/language",currentLocale);

    System.out.println(resourceBundle.getString( "greetings" ));
}

i do this

language = new String("pl");

because this

Locale.ENGLISH

dont have an Static Locale.POLISH

i also will be save for example (Germany or de|Polish or pl|English or en) as an Setting

with this stateManager.setPersistenceMode( StateManager.PersistenceMode.USER); stateManager.setProperty( "language", "de" );

or better as Programm Settings not in user C:\Users\Harry05.gluon-particle