use of org.olat.core.util.i18n.I18nManager in project openolat by klemens.
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
}
use of org.olat.core.util.i18n.I18nManager in project openolat by klemens.
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);
}
use of org.olat.core.util.i18n.I18nManager in project OpenOLAT by OpenOLAT.
the class I18nWebService method getTranslation.
/**
* Return the translation of the key. If the "locale" parameter is not specified, the method
* try to use the "locale" of the user and if it hasn't, take the default locale.
* @response.representation.200.mediaType text/plain
* @response.representation.200.doc The translation of the package + key
* @response.representation.200.example OK
* @param packageName The name of the package
* @param key The key to translate
* @param localeKey The locale (optional)
* @param request The HTTP request (optional)
* @return
*/
@GET
@Path("{package}/{key}")
@Produces(MediaType.TEXT_PLAIN)
public Response getTranslation(@PathParam("package") String packageName, @PathParam("key") String key, @QueryParam("locale") String localeKey, @Context HttpServletRequest request) {
I18nManager i18n = CoreSpringFactory.getImpl(I18nManager.class);
I18nModule i18nModule = CoreSpringFactory.getImpl(I18nModule.class);
Locale locale = null;
if (StringHelper.containsNonWhitespace(localeKey)) {
locale = i18n.getLocaleOrDefault(localeKey);
} else {
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
if (ureq != null && ureq.getLocale() != null) {
locale = ureq.getLocale();
}
}
if (locale == null) {
locale = i18nModule.getDefaultLocale();
}
boolean overlayEnabled = i18nModule.isOverlayEnabled();
String val = i18n.getLocalizedString(packageName, key, EMPTY_ARRAY, locale, overlayEnabled, true);
return Response.ok(val).build();
}
use of org.olat.core.util.i18n.I18nManager in project OpenOLAT by OpenOLAT.
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();
}
use of org.olat.core.util.i18n.I18nManager in project OpenOLAT by OpenOLAT.
the class WikiPageComparator method compare.
/**
* Compares the name of page 'a' to that of page 'b' with respect to the
* current locale (different languages have different alphabets and hence
* different orders).
*
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(WikiPage a, WikiPage b) {
// Be aware of locale when ordering
I18nManager mgr = I18nManager.getInstance();
Locale userLocale = mgr.getCurrentThreadLocale();
Collator collator = Collator.getInstance(userLocale);
collator.setStrength(Collator.PRIMARY);
// Undefinied order if page a or b is null
int order = 0;
if (a != null && b != null) {
final String nameA = a.getPageName();
final String nameB = b.getPageName();
// Compare page names with the localized comparator
order = collator.compare(nameA, nameB);
}
return order;
}
Aggregations