Search in sources :

Example 1 with I18nManager

use of org.olat.core.util.i18n.I18nManager in project OpenOLAT by OpenOLAT.

the class VelocityRenderDecorator method getLanguages.

public Languages getLanguages() {
    I18nManager i18nMgr = CoreSpringFactory.getImpl(I18nManager.class);
    I18nModule i18nModule = CoreSpringFactory.getImpl(I18nModule.class);
    Collection<String> enabledKeysSet = i18nModule.getEnabledLanguageKeys();
    Map<String, String> langNames = new HashMap<String, String>();
    Map<String, String> langTranslators = new HashMap<String, String>();
    String[] enabledKeys = ArrayHelper.toArray(enabledKeysSet);
    String[] names = new String[enabledKeys.length];
    for (int i = 0; i < enabledKeys.length; i++) {
        String key = enabledKeys[i];
        String langName = i18nMgr.getLanguageInEnglish(key, i18nModule.isOverlayEnabled());
        langNames.put(key, langName);
        names[i] = langName;
        String author = i18nMgr.getLanguageAuthor(key);
        langTranslators.put(key, author);
    }
    ArrayHelper.sort(enabledKeys, names, true, true, true);
    return new Languages(enabledKeys, langNames, langTranslators);
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) HashMap(java.util.HashMap) I18nManager(org.olat.core.util.i18n.I18nManager)

Example 2 with I18nManager

use of org.olat.core.util.i18n.I18nManager in project OpenOLAT by OpenOLAT.

the class MoveLanguagesVisitor method visit.

/**
 * @see org.olat.core.util.FileVisitor#visit(java.io.File)
 */
public void visit(File file) {
    if (file.isFile()) {
        // regular file
        String toBeChechedkFilName = file.getName();
        I18nManager i18nMgr = I18nManager.getInstance();
        String computedFileName = i18nMgr.buildI18nFilename(moveLanguage);
        // match?
        if (toBeChechedkFilName.equals(computedFileName)) {
            File parentFile = file.getParentFile();
            String pPath = parentFile.getPath();
            String relTargetPath = "";
            if (!basePath.equals(pPath)) {
                String res = pPath.substring(basePath.length() + 1);
                relTargetPath = relTargetPath + "/" + res;
            }
            File targetFile = new File(targetDir, relTargetPath);
            if (doMoveNoCopy) {
                FileUtils.moveFileToDir(file, targetFile);
                log.info("moving " + file.toString() + " to " + targetFile.getAbsolutePath());
            } else {
                FileUtils.copyFileToDir(file, targetFile, "move i18n file");
                log.info("copying " + file.toString() + " to " + targetFile.getAbsolutePath());
            }
        }
    }
// else ignore
}
Also used : File(java.io.File) I18nManager(org.olat.core.util.i18n.I18nManager)

Example 3 with I18nManager

use of org.olat.core.util.i18n.I18nManager in project OpenOLAT by OpenOLAT.

the class JSTranslatorMapper method handle.

/**
 * @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String, javax.servlet.http.HttpServletRequest)
 */
public MediaResource handle(String relPath, HttpServletRequest request) {
    I18nManager i18nManager = I18nManager.getInstance();
    // Get bundle and locale
    String[] parts = relPath.split("/");
    String localeKey = parts[1];
    String bundleName = parts[2];
    Locale locale = i18nManager.getLocaleOrDefault(localeKey);
    // Get the translation data
    JSONObject translationData = i18nManager.getJSONTranslatorData(locale, bundleName);
    return new JSONMediaResource(translationData, "UTF-8");
}
Also used : Locale(java.util.Locale) JSONObject(org.json.JSONObject) JSONMediaResource(org.olat.core.gui.media.JSONMediaResource) I18nManager(org.olat.core.util.i18n.I18nManager)

Example 4 with I18nManager

use of org.olat.core.util.i18n.I18nManager in project OpenOLAT by OpenOLAT.

the class LoginAuthprovidersController method showAboutPage.

protected void showAboutPage() {
    VelocityContainer aboutVC = createVelocityContainer("about");
    // Add version info and licenses
    aboutVC.contextPut("version", Settings.getFullVersionInfo());
    // Add translator and languages info
    I18nManager i18nMgr = I18nManager.getInstance();
    Collection<String> enabledKeysSet = i18nModule.getEnabledLanguageKeys();
    Map<String, String> langNames = new HashMap<String, String>();
    Map<String, String> langTranslators = new HashMap<String, String>();
    String[] enabledKeys = ArrayHelper.toArray(enabledKeysSet);
    String[] names = new String[enabledKeys.length];
    for (int i = 0; i < enabledKeys.length; i++) {
        String key = enabledKeys[i];
        String langName = i18nMgr.getLanguageInEnglish(key, i18nModule.isOverlayEnabled());
        langNames.put(key, langName);
        names[i] = langName;
        String author = i18nMgr.getLanguageAuthor(key);
        langTranslators.put(key, author);
    }
    ArrayHelper.sort(enabledKeys, names, true, true, true);
    aboutVC.contextPut("enabledKeys", enabledKeys);
    aboutVC.contextPut("langNames", langNames);
    aboutVC.contextPut("langTranslators", langTranslators);
    dmzPanel.pushContent(aboutVC);
}
Also used : HashMap(java.util.HashMap) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) I18nManager(org.olat.core.util.i18n.I18nManager)

Example 5 with I18nManager

use of org.olat.core.util.i18n.I18nManager in project openolat by klemens.

the class PreferencesImpl method setLanguage.

/**
 * Set users language settings
 * @param l new language
 */
public void setLanguage(String l) {
    // validate the language; fallback to default
    I18nManager i18n = I18nManager.getInstance();
    this.language = i18n.getLocaleOrDefault(l).toString();
}
Also used : I18nManager(org.olat.core.util.i18n.I18nManager)

Aggregations

I18nManager (org.olat.core.util.i18n.I18nManager)14 Locale (java.util.Locale)6 HashMap (java.util.HashMap)4 I18nModule (org.olat.core.util.i18n.I18nModule)4 File (java.io.File)2 Collator (java.text.Collator)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JSONObject (org.json.JSONObject)2 UserRequest (org.olat.core.gui.UserRequest)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 JSONMediaResource (org.olat.core.gui.media.JSONMediaResource)2