Adding custom languages to Boomega

April 25, 2022 · View on GitHub

This page will guide you how to contribute languages to the app, and also gives you a basis for developing language-plugins.

Prerequisites

These apply to you only if you're contributing to the core project:

Property files

Firstly, create your own .properties file that contains the translations. View the default resource file to have an idea.

These apply to you only if you're contributing to the core project:

The LanguagePack class

After you've created the properties-file, you have to create your LanguagePack. A LanguagePack in Boomega provides the ResourceBundle (representing the .properties file) and other things needed for defining a language.

This applies to you only if you're contributing to the core project:

A simple example:

Kotlin Java
class PortugueseLanguagePack : LanguagePack(Locale("pt"), AUTHOR) {

    // The com/dansoftware/boomega/i18n/MyValues_pt.properties file
    override fun getValues(): ResourceBundle = super.getBundle("com.dansoftware.boomega.i18n.MyValues")

    override fun isRTL(): Boolean = false // Portuguese is not a right-to-left language

    companion object {
        // represents the person who translated the language
        private val AUTHOR = Person(
            lastName = "LastName",
            firstName = "FirstName",
            email = "myemail@example.com"
        )
    }
}
public class PortugueseLanguagePack extends LanguagePack {

    // the Locale representing the language we want to translate to (in this case Portuguese)
    private static final Locale LOCALE = new Locale("pt");

    // represents the person who translated the language
    private static final Person AUTHOR = new Person("LastName", "FirstName", "myemail@example.com");

    protected PortugueseLanguagePack() {
        super(LOCALE, AUTHOR);
    }

    @Override
    public @NotNull
    ResourceBundle getValues() {
        //The com/dansoftware/boomega/i18n/MyValues_pt.properties file
        return super.getBundle("com.dansoftware.boomega.i18n.MyValues");
    }

    @Override
    protected boolean isRTL() {
        return false; // Portuguese is not a right-to-left language
    }
}

Specifying the alphabetical order

Knowing the alphabetical order for Boomega is crucial for several features (e.g. sorting records in a table-view).
Defining ABCs in Java is possible with the help of Collators. By overriding the LanguagePack.getABCCollator() method you can specify the Collator for your language-pack.
If you don't specify any collator for your pack, the default collator will be used which is Collator.getInstance().

Look at this simplified snippet from the internal HungarianLanguagePack:

public class HungarianLanguagePack extends LanguagePack {

  ...

    @Override
    public @NotNull
    Collator getABCCollator() {
        return new NullHandlingCollator(new ABCCollator());
    }

  ...

    private static final class ABCCollator extends RuleBasedCollator {
        ABCCollator() throws ParseException {
            super("""
                    < a,A < á,Á < b,B < c,C < cs,Cs,CS < d,D < dz,Dz,DZ < dzs,Dzs,DZS \
                    < e,E < é,É < f,F < g,G < gy,Gy,GY < h,H < i,I < í,Í < j,J \
                    < k,K < l,L < ly,Ly,LY < m,M < n,N < ny,Ny,NY < o,O < ó,Ó \
                    < ö,Ö < ő,Ő < p,P < q,Q < r,R < s,S < sz,Sz,SZ < t,T \
                    < ty,Ty,TY < u,U < ú,Ú < ü,Ü < ű,Ű < v,V < w,W < x,X < y,Y < z,Z < zs,Zs,ZS\
                    """
            );
        }
    }
}

Notice that it wraps the base collator into a NullHandlingCollator for preventing possible null-pointer exceptions when comparing null values with the collator in the future. You should also follow this practice with your own collator.

Registering your language-pack

This page applies to you only if you're contributing to the core project.

After you've created your pack implementation you have to register it's full class-name in the internal_lang_packs.json config file.

Like this:

{
  ...
  "classNames": [
    ...
    "com.dansofware.boomega.i18n.PortugueseLanguagePack"
  ]
}

Other examples

You can view the internal LanguagePack implementations (for understanding the concepts better) in the com.dansoftware.boomega.i18n package e.g:


Now, if you want to add your language through plugins, check out the plugin guide for further instructions.