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
- Understand the concept of ResourceBundles in java (this article might help you in this)
These apply to you only if you're contributing to the core project:
- Make sure you've read the contribution guideline
- Work in the
boomega-i18nsubproject
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:
- Name your property files according to this pattern:
Values<postfix>.properties - Make sure you add the locale-specific postfix to your file (e.g
Values_en_US.properties) - Place your property files to
the
resources/com/dansoftware/boomega/i18ndirectory
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:
- Locate your LanguagePack to
the
com.dansofware.boomega.i18npackage
A simple example:
| Kotlin | Java |
|---|---|
|
|
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.