Search in sources :

Example 1 with Language

use of org.cubeengine.i18n.language.Language in project core by CubeEngine.

the class I18n method getLanguage.

public Language getLanguage(Locale locale) {
    try {
        Language language = this.service.getLanguage(locale);
        if (language != null) {
            this.languageLookupMap.put(language.getName().toLowerCase(language.getLocale()), language);
            this.languageLookupMap.put(language.getLocalName().toLowerCase(language.getLocale()), language);
        }
        return language;
    } catch (TranslationLoadingException | DefinitionLoadingException e) {
        log.error(e, "Error while getting Language!");
        return null;
    }
}
Also used : SourceLanguage(org.cubeengine.i18n.language.SourceLanguage) Language(org.cubeengine.i18n.language.Language) DefinitionLoadingException(org.cubeengine.i18n.language.DefinitionLoadingException) TranslationLoadingException(org.cubeengine.i18n.translation.TranslationLoadingException)

Example 2 with Language

use of org.cubeengine.i18n.language.Language in project core by CubeEngine.

the class I18n method searchLanguages.

public Set<Language> searchLanguages(String name, int maxDistance) {
    Locale locale = I18nUtil.stringToLocale(name.toLowerCase());
    Language language = this.getLanguage(locale);
    if (language != null) {
        HashSet<Language> lang = new HashSet<>();
        lang.add(language);
        return lang;
    }
    Set<String> matches = stringMatcher.getBestMatches(name.toLowerCase(), this.languageLookupMap.keySet(), maxDistance);
    Set<Language> languages = new HashSet<>(matches.size());
    for (String match : matches) {
        languages.add(this.languageLookupMap.get(match));
    }
    return languages;
}
Also used : Locale(java.util.Locale) SourceLanguage(org.cubeengine.i18n.language.SourceLanguage) Language(org.cubeengine.i18n.language.Language) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with Language

use of org.cubeengine.i18n.language.Language in project core by CubeEngine.

the class I18n method registerPlugin.

public void registerPlugin(PluginContainer plugin) {
    String name = plugin.getName();
    for (Language language : getLanguages()) {
        String lang = language.getLocale().getLanguage();
        String full = lang + "_ " + language.getLocale().getCountry();
        Optional<Asset> asset = getAssetManager().getAsset(plugin, "translations/" + lang + "_" + name + ".po");
        asset.map(Asset::getUrl).ifPresent(poFiles::add);
        asset = getAssetManager().getAsset(plugin, "translations/" + full + "_" + name + ".po");
        asset.map(Asset::getUrl).ifPresent(poFiles::add);
    }
}
Also used : SourceLanguage(org.cubeengine.i18n.language.SourceLanguage) Language(org.cubeengine.i18n.language.Language) Asset(org.spongepowered.api.asset.Asset)

Aggregations

Language (org.cubeengine.i18n.language.Language)3 SourceLanguage (org.cubeengine.i18n.language.SourceLanguage)3 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Locale (java.util.Locale)1 DefinitionLoadingException (org.cubeengine.i18n.language.DefinitionLoadingException)1 TranslationLoadingException (org.cubeengine.i18n.translation.TranslationLoadingException)1 Asset (org.spongepowered.api.asset.Asset)1