Properties file based translations for the Unity game engine.
Properties files are simple, industry proven in Java, and well supported by many localization tools.
- Get strings for different languages from properties files
- Support regional dialects and fallback chains
- For example
en-US
anden-GB
can fall back to commonen
for a missing translation
- For example
- Add a new language or regional dialect by adding a properties file with corresponding suffix
- Sensible defaults for missing translations
- Simple static methods that can be accessed from anywhere
- Usable on any thread, not only on the main thread
- Built on top of System.Globalization.CultureInfo
# Example properties file
hello = Hello {name}!
multilineUsingNewline = First line\nSecond line
multilineUsingBackslash = First line\
Second line
umlautDirectlyInUtf8File = Äpfel
umlautAsEscapedAscii = \u00C4pfel
colonAsSeparator: Separate key and value via colon or equals
// Get translations via static methods
Translation.Get("multilineUsingNewline");
// Specify placeholders via varargs or a dictionary
Translation.Get("hello", "name", "Alice");
Translation.Get("hello", new Dictionary<string, string>() { {"name", "Alice"} });
// Change current language and other configuration via static properties
TranslationConfig.Singleton.CurrentCultureInfo = new CultureInfo("en-US");
- You can add a dependency to your
Packages/manifest.json
using a Git URL in the following form:"com.achimmihca.protrans": "https://github.com/achimmihca/ProTrans.git?path=ProTrans/Packages/com.achimmihca.ProTrans"
- Note that
#v1.0.0
can be used to specify a tag or commit hash.
- Note that
- See TranslationConfig for available properties
- By default, properties files are expected in
StreamingAssets/Translations
and with namemessages.properties
,messages_de_CH.properties
, etc.- This can be changed by setting
TranslationConfig.PropertiesFileProvider
- This can be changed by setting
- By default, the base properties file (i.e. without any language and region suffix) is expected to contain English translations.
- This can be changed by setting
TranslationConfig.DefaultCultureInfo
- This can be changed by setting
- By default a language is searched in the following order
- (1) currently selected language (e.g.
messages_de_CH.properties
) - (2) without the region suffix (e.g.
messages_de.properties
) - (3) without any suffix (e.g.,
messages.properties
) - This can be changed by setting
TranslationConfig.FallbackCultureInfoProvider
- (1) currently selected language (e.g.
- Use underscores and two letter country codes as suffix for different languages and regional dialects.
- Example:
messages.properties
is the default (and fallback) language,messages_de.properties
is for German translations,messages_de_CH.properties
is for German as spoken in Switzerland. - See also
CultureInfo.GetCultures(CultureTypes.AllCultures)
- Example:
ProTrans has been created originally for UltraStar Play. If you like singing, karaoke, or sing-along games then go check it out ;)