How could i translate WebLaF into another language?

Some of frequently asked questions are saved here.
You might find some answers for your questions in this forum.

How could i translate WebLaF into another language?

Postby mgarin » Mon Oct 29, 2012 3:05 pm

How to

Components translation It is pretty simple thing to do in WebLaF and shouldn't take much time. I tried to make the LanguageManager and translation system as flexible as it could be and here what we've got...

Xml-based translation
(default for WebLaF core)

The only thing you really need to do - change the language.xml file in WebLaF library which is stored here:

You can also find this file in GitHub project sources here: ... nguage.xml

That is needed only if you are going to change core WebLaF translation. You don't need to change that file in case you only want to add your own components translation.

It is a simple translation xml file that could be easily understood by just looking at its constructions. For example, here is a small part of it that adds a translation for version info dialog:
Code: Select all
<Dictionary name="Web Look and Feel language" prefix="weblaf" author="Alee Software" creationDate="27.04.2012">
    <Dictionary name="Library information frame" prefix="info">
        <record key="title">
            <value lang="ru">Информация о библиотеке</value>
            <value lang="en">Library information</value>
            <value lang="pl">Informacje o bibliotece</value>
        <record key="updated">
            <value lang="ru">Обновлена:</value>
            <value lang="en">Updated:</value>
            <value lang="pl">Zaktualizowano:</value>
        <record key="java.version">
            <value lang="ru">Java v.</value>
            <value lang="en">Java v.</value>
            <value lang="pl">Java v.</value>
        <record key="os.arch">
            <value lang="ru">Архитектура:</value>
            <value lang="en">Architecture:</value>
            <value lang="pl">Architektura:</value>

You can see a few basic constructions here: dictionaries, records and values. Also (in more complicated cases) values might a list of texts and tooltips instead of a simple text line.

Available structures

Most of those constructions also have attributes available, let me describe each of them separately:

    prefix - dictionary prefix - used for language key path
    id - dictionary unique id - it is usually not required
    name - dictionary name - not required, just an information field
    author - dictionary author - not required, just an information field
    creationDate - dictionary creation date - not required, just an information field
    notes - notes about the dictionary - not required, just an information field
    records (list) - dictionary records
    dictionaries (list) - sub-dictionaries
Every dictionary might contain any amount of records and sub-dictionaries at any place.

    key - record key - used for language key path
    hotkey - record hotkey - not required, hotkey for translation target component
    values (list) - record values
Every record might contain any amount of values.

    lang - value language - used for value selection on translation
    mnemonic - value mnemonic - not required, mnemonic for translation target component
    hotkey - value-specific hotkey - not required, hotkey for translation target component
    texts (list) - value texts
    tooltips (list) - value tooltips
Every value might contain either simple text or any amount of texts and tooltips at any place.
If value lang attribute is not specified that value is considered to be default for all languages.

    text - text value - final translation for certain language and state
    state - state for the text - not required, component state for this text value
Usually state value is not used in translation but it might be useful for custom components.

    text - tooltip text value - final tooltip translation for certain language
    type - tooltip type - not required, either swing or weblaf constant
    way - tooltip display way - not required, either up, left, right, down, leading or trailing constant
    delay - tooltip display delay - not required, delay in ms
You can specify type attribute to ensure that you will have either Swing or WebLaF tooltip. WebLaF is the default one though. Though you can always change that using LanguageManager.setDefaultTooltipType method.

More complicated example

You can see a more complicated example of language usage (that contains some of the features i have described before) in demo application.

Here is an example language.xml file from the demo application:
Code: Select all
<Dictionary name="My language" prefix="my" author="mgarin" creationDate="29.10.2012">
    <record key="button" hotkey="ctrl D">
        <value lang="ru" mnemonic="д">
            <text>Показать диалог</text>
            <tooltip way="up" delay="0">Кнопка показа диалога</tooltip>
        <value lang="en" mnemonic="d">
            <text>Show dialog</text>
            <tooltip way="up" delay="0">Dialog display button</tooltip>
    <Dictionary name="My dialog language" prefix="dialog">
        <record key="title">
            <value lang="ru">Просто диалог</value>
            <value lang="en">Just another dialog</value>
        <record key="text">
                <text><![CDATA[>>>>>>> <<<<<<<]]></text>
                <text state="rollover"><![CDATA[<<<<<<< >>>>>>>]]></text>

Code-based translation

You can also do all the translations using the core WebLaF classes which represent default language structures i told about before (they have all the described fields):
Code: Select all

There are a lot of custom constructors and methods in those classes which will help you to quickly create your custom dictionaries. First of all create a Dictionary instance:
Code: Select all
Dictionary dictionary = new Dictionary ( "my" );

Now you can add some records in lots of different ways:
Code: Select all
dictionary.addRecord ( "text", "ru", "Текст" );
dictionary.addRecord ( "text", "en", "Text" );

Code: Select all
dictionary.addRecord ( "text", new Value ( "ru", "Текст" ), new Value ( "en", "Text" ) );

Code: Select all
dictionary.addRecord ( new Record ( "text", new Value ( "ru", "Текст" ), new Value ( "en", "Text" ) ) );

And finally, add your dictionary into LanguageManager:
Code: Select all
LanguageManager.addDictionary ( dictionary );

Now you can use the key "my.text" to register some component or request that key tranlation for current active language. It works exactly in the same way with xml-based translations.

Language editor

It is the third way to create a translation without ever editing xml and code - use the visual editor that is provided with WebLaF library to create your own fully functional dictionaries. You can find it in the demo application "Language" tab (coming soon!).

Adding new languages into WebLaF

I would really appreciate if you post your modified WebLaF language.xml file here so i can add more supported languages right into default WebLaF library.
User avatar
Site Admin
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: How could i translate WebLaF into another language?

Postby trashguru » Sun Jul 28, 2013 9:19 pm

I translated the File to german.
Hope this might help and gets included in future releases.
I couldn't really test it, so no guarantee, but as a native german it should be woth more than a missing language ;)
(67.35 KiB) Downloaded 436 times
Posts: 1
Joined: Sun Jul 28, 2013 8:42 pm

Re: How could i translate WebLaF into another language?

Postby mgarin » Tue Jul 30, 2013 2:44 pm

Thanks for the german translation! :)
I have added it into the project and added its support in WebLaF.

You can find those changes in GitHub repository here:
I will add an updated build there a bit later.

To use german as a default language you can simply setup it before installing WebLaF as L&F like this:
Code: Select all
LanguageManager.DEFAULT = LanguageManager.GERMAN;

To switch language in runtime (after installing WebLaF) you can use this LanguageManager method:
Code: Select all
LanguageManager.setLanguage ( LanguageManager.GERMAN );

Be aware that if you set language after the WebLaF initialization it will force default language to load first into LanguageManager and take some precious processor time.
User avatar
Site Admin
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Return to FAQ

Who is online

Users browsing this forum: No registered users and 1 guest