use of org.terasology.engine.i18n.TranslationProject in project Terasology by MovingBlocks.
the class LocaleConstraintWidgetFactory method buildWidget.
@Override
protected Optional<UIWidget> buildWidget() {
Setting<Locale> setting = getSetting();
Binding<Locale> binding = new Binding<Locale>() {
@Override
public Locale get() {
return setting.get();
}
@Override
public void set(Locale value) {
setting.set(value);
}
};
UIDropdownScrollable<Locale> dropdownScrollable = new UIDropdownScrollable<>();
ResourceUrn menuUrn = new ResourceUrn("engine:menu");
TranslationProject menuProject = translationSystem.getProject(menuUrn);
List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
for (Locale languageExcluded : languagesExcluded) {
locales.remove(languageExcluded);
}
Collections.sort(locales, (Comparator.comparing((Function<Object, String>) Object::toString)));
dropdownScrollable.setOptions(Lists.newArrayList(locales));
// Set maximum number of options visible for scrolling
dropdownScrollable.setVisibleOptions(5);
dropdownScrollable.bindSelection(binding);
dropdownScrollable.setOptionRenderer(new LocaleRenderer(translationSystem));
return Optional.of(dropdownScrollable);
}
use of org.terasology.engine.i18n.TranslationProject in project Terasology by MovingBlocks.
the class CoreCommands method setLanguage.
/**
* Change the UI language
*
* @param langTag String containing language code to change
* @return String containing language or if not recognized error message
*/
@Command(shortDescription = "Changes the UI language")
public String setLanguage(@CommandParam("language-tag") String langTag) {
Locale locale = Locale.forLanguageTag(langTag);
TranslationProject proj = translationSystem.getProject(new ResourceUrn("engine:menu"));
// Try if language exists
if (proj.getAvailableLocales().contains(locale)) {
systemConfig.locale.set(locale);
nuiManager.invalidate();
String nat = translationSystem.translate("${engine:menu#this-language-native}", locale);
String eng = translationSystem.translate("${engine:menu#this-language-English}", locale);
return String.format("Language set to %s (%s)", nat, eng);
} else {
return "Unrecognized locale! Try one of: " + proj.getAvailableLocales();
}
}
use of org.terasology.engine.i18n.TranslationProject in project Terasology by MovingBlocks.
the class NUIEditorSettingsScreen method initialise.
@Override
public void initialise() {
WidgetUtil.tryBindCheckbox(this, "disableAutosave", BindHelper.bindBeanProperty("disableAutosave", config.getNuiEditor(), Boolean.TYPE));
WidgetUtil.tryBindCheckbox(this, "disableIcons", BindHelper.bindBeanProperty("disableIcons", config.getNuiEditor(), Boolean.TYPE));
WidgetUtil.trySubscribe(this, "close", button -> getManager().closeScreen(ASSET_URI));
alternativeLocale = find("alternativeLocale", UIDropdownScrollable.class);
if (alternativeLocale != null) {
// Build the list of available locales and set the dropdown's options to them.
TranslationProject menuProject = translationSystem.getProject(new ResourceUrn("engine:menu"));
List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
Collections.sort(locales, ((Object o1, Object o2) -> (o1.toString().compareTo(o2.toString()))));
alternativeLocale.setOptions(Lists.newArrayList(locales));
alternativeLocale.setVisibleOptions(5);
alternativeLocale.setOptionRenderer(new LocaleRenderer(translationSystem));
// If an alternative locale has been previously selected, select it; otherwise select the system locale.
if (config.getNuiEditor().getAlternativeLocale() != null) {
alternativeLocale.setSelection(config.getNuiEditor().getAlternativeLocale());
} else {
alternativeLocale.setSelection(systemConfig.locale.get());
}
}
}
Aggregations