Example usage for com.liferay.portal.kernel.util LocaleUtil toW3cLanguageId

List of usage examples for com.liferay.portal.kernel.util LocaleUtil toW3cLanguageId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util LocaleUtil toW3cLanguageId.

Prototype

public static String toW3cLanguageId(String languageId) 

Source Link

Usage

From source file:com.liferay.frontend.taglib.servlet.taglib.soy.TranslationManagerTag.java

License:Open Source License

@Override
public int doStartTag() {
    JSONArray availableLocalesJSONArray = JSONFactoryUtil.createJSONArray();
    JSONObject localesJSONObject = JSONFactoryUtil.createJSONObject();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Set<Locale> locales = LanguageUtil.getAvailableLocales(themeDisplay.getSiteGroupId());

    for (Locale locale : locales) {
        String languageId = LocaleUtil.toLanguageId(locale);

        if (ArrayUtil.contains(_availableLocales, locale)) {
            availableLocalesJSONArray.put(languageId);
        }/*from  w w  w  . ja va  2s  . c om*/

        JSONObject localeJSONObject = JSONFactoryUtil.createJSONObject();

        String w3cLanguageId = LocaleUtil.toW3cLanguageId(locale);

        localeJSONObject.put("code", w3cLanguageId);
        localeJSONObject.put("icon", StringUtil.toLowerCase(w3cLanguageId));

        localeJSONObject.put("id", languageId);
        localeJSONObject.put("name", locale.getDisplayName(themeDisplay.getLocale()));

        localesJSONObject.put(languageId, localeJSONObject);
    }

    putValue("availableLocales", availableLocalesJSONArray);
    putValue("locales", localesJSONObject);

    putValue("pathThemeImages", themeDisplay.getPathThemeImages());

    setTemplateNamespace("TranslationManager.render");

    return super.doStartTag();
}

From source file:com.liferay.users.admin.web.internal.theme.contributor.UsersTemplateContextContributor.java

License:Open Source License

@Override
public void prepare(Map<String, Object> contextObjects, HttpServletRequest request) {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    User user = themeDisplay.getUser();/*from w ww . java2  s  . co m*/

    contextObjects.put("is_default_user", user.isDefaultUser());

    try {
        Contact contact = user.getContact();

        contextObjects.put("is_female", !contact.isMale());
        contextObjects.put("is_male", contact.isMale());
        contextObjects.put("user_birthday", contact.getBirthday());
    } catch (PortalException pe) {
        _log.error(pe, pe);
    }

    contextObjects.put("is_setup_complete", user.isSetupComplete());
    contextObjects.put("language", themeDisplay.getLanguageId());
    contextObjects.put("language_id", user.getLanguageId());
    contextObjects.put("user_comments", user.getComments());
    contextObjects.put("user_email_address", user.getEmailAddress());
    contextObjects.put("user_first_name", user.getFirstName());
    contextObjects.put("user_greeting", HtmlUtil.escape(user.getGreeting()));
    contextObjects.put("user_id", user.getUserId());
    contextObjects.put("user_initialized", true);
    contextObjects.put("user_last_login_ip", user.getLastLoginIP());
    contextObjects.put("user_last_name", user.getLastName());
    contextObjects.put("user_login_ip", user.getLoginIP());
    contextObjects.put("user_middle_name", user.getMiddleName());
    contextObjects.put("user_name", user.getFullName());

    Group group = themeDisplay.getSiteGroup();

    if (group.isUser()) {
        try {
            User user2 = _userLocalService.getUserById(group.getClassPK());

            contextObjects.put("user2", user2);
        } catch (PortalException pe) {
            _log.error(pe, pe);
        }
    }

    contextObjects.put("w3c_language_id", LocaleUtil.toW3cLanguageId(themeDisplay.getLanguageId()));
}