Show Localized value for HybrisEnumValue in Hybris Backoffice - localization

We are trying to show the localized value for a "dynamic" enum.
In our backoffice-config.xml We have something like this
<context type="CustomeType" component="base" merge-by="type">
<y:base xmlns:y="http://www.hybris.com/cockpit/config/hybris">
<y:labels>
<y:label>customProperty.hybrisEnumValueProperty.name</y:label>
</y:labels>
</y:base>
</context>
With this we receive the default TypeName(Pk) in backoffice instead of the localized name. For the code it works just fine. Also for hmc it works as well.

You need to add localization text for these enums like below.
mycoreextension-items.xml
<enumtype code="myenum" generate="true" dynamic="true">
<value code="ENUM1" />
<value code="ENUM2" />
</enumtype>
mycoreextension-locales_en.properties
type.myenum.name=My Enum Name
type.myenum.description=My enum description
type.myenum.enum1.name=My enum value 1
type.myenum.enum2.name=My enum value 1

Related

Syntax - How to combine Binding with Localization?

I need to combine localization with binding. I have the following xml:
<Label Text="{Binding TravelOrder.StartDate, StringFormat='Start Date: {0:d}'}" />
I would like to have the string format localized, i.e. instead of "Start Date" to have, for instance, for French, "Date de debut".
How can I put something like {x:Static res:AppRes.StartDate} inside my StringFormat value ?
I have tried to write something like
Text="{Binding TravelOrder.StartDate, StringFormat='{x:Static res:AppRes.StartDate}: {0:d}'}" />
but clearly that doesn't work.
Thank you.

Why I am getting MissingResourceException locale en_US when I have defined default locale as es_ES? [duplicate]

i wanted to set the default location of my jsf web project to english, so
i did the following:
faces-config.xml
<application>
<locale-config>
<default-locale>en_EN</default-locale>
<supported-locale>de_DE</supported-locale>
</locale-config>
<resource-bundle>
<base-name>de.hof.tschuwwa.resources.messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
i have a package in my src folder de.hof.tschuwwa.resources and inside
of that package i have two property files:
messages_de_DE.properties
messages_en_EN.properties
and i tested it in a small xhtml file:
<h:body>
<ui:composition template="/templates/master.xhtml">
<ui:define name="header">
<h:form>
<h:commandButton action="#{navigationService.toLogin}" value="#{msg['login']}" />
<h:commandButton action="#{navigationService.toRegister}" value="#{msg['register']}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
When i start my application it shows the german values and not
the english values. i wanted the default language to be english.
How can i set my default language? The faces-config.xml default-locale
does not seem to work.
Also i need to know how i can change my localization. i wrote this small
service:
#Named
#SessionScoped
public class LanguageService implements Serializable {
private static final long serialVersionUID = 1L;
public void changeLanguage(String language) {
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(language));
}
}
and tried out with the following buttons inside a form:
<p:commandButton id="english" value="English" action="#{languageService.changeLanguage('en')}" immediate="true" />
<p:commandButton id="german" value="Deutsch" action="#{languageService.changeLanguage('de')}" immediate="true" />
but nothing happened when i used them.
<default-locale>en_EN</default-locale>
First of all, you've there a mistake in the locale identifier en_EN. The first two lowercase characters represent the ISO 693-1 language code. It is optional and only required whenever the country code is present. The last two uppercased characters represent the ISO 3166-1 Alpha-2 country code. It is optional and often only used to distinguish between country-specific language dialects, like American English (en_US) and British English (en_GB). There's no such country like "England", so en_EN is definitely invalid. You most likely want to use en or perhaps en_US here.
Thus, so
<default-locale>en</default-locale>
with an appropriate messages_en.properties file.
How can i set my default language? The faces-config.xml default-locale does not seem to work.
The <default-locale> is only used when the client didn't supply the locale by itself in flavor of the Accept-Language HTTP request header, or supplied one which isn't supported by the application as definied in <supported-locale>. A lot of (sane) clients actually set the Accept-Language header. With a HTTP traffic monitor you can see them.
(the screen says: en-US is the first preference (with a default "weight" of 1), the en is the second preference with a "weight" of 0.8, the nl is the third preference with a "weight" of 0.6; in Chrome you can change this in chrome://settings/languages by adding/removing/reordering languages).
If you want to prevent this and want to force the "default" locale for some unclear reason, then you'd need to explicitly set the <f:view locale> to the desired "default" locale (note: you're thus actually overriding client's preferred locale as configured in its program — the webbrowser).
E.g.:
<f:view locale="#{languageService.language}">
(just put in master template, wrapping the <h:head> and <h:body>)
with this new property in your backing bean:
#Named
#SessionScoped
public class LanguageService implements Serializable {
private Locale locale;
#PostConstruct
public void init() {
locale = FacesContext.getCurrentInstance().getApplication().getDefaultLocale();
}
// ...
}
Also i need to know how i can change my localization.
Your mistake in this particular example is that you're not updating the view after invoking the action. You need to add update="#all" to the command buttons. But there's another mistake: you're not remembering the locale for subsequent requests. It would fall back to the "default" locale again. You need to set the <f:view locale> with this property. This is already answered in detail before: Localization in JSF, how to remember selected locale per session instead of per request/view.

Parse HTML stored as string in Database in ColdFusion

I have taken over this ColdFusion project and found that I need a value out of a database field that includes HTML. The field data looks like this (without the new lines):
<wddxPacket version="1.0">
<header />
<data>
<struct>
<var name="en">
<string>3 Nights' Lodging</string>
</var>
<var name="sp">
<string>3 Noches alojamiento</string>
</var>
</struct>
</data>
</wddxPacket>
I am wanting to use this data but I only need the text between the:
<var name='en'><string>3 Nights' Lodging</string></var>
I used a function that ColdFusion has to remove HTML:
#REReplaceNoCase(pkg.title, "<[^><]*>", '', 'ALL')#
But when I use that, I get something like this:
3 Nights' Lodging3 Noches alojamiento
All I want is:
3 Nights' Lodging
Examining the beginning of the string, ie <wddxPacket ...> it is actually WDDX.
If you do a search for ColdFusion + WDDX you will find the documentation for CFWDDX. It is a built in tag which supports conversions of WDDX strings to CFML objects (and vice versa) for easier manipulation. In your case use action="wddx2cfml" to convert the string back into a CF structure.
<cfwddx action="wddx2cfml" input="#text#" output="result">
<cfdump var="#result#" label="Raw object">
Then use the key #result.en# to grab the string you want.

how to localise texts fetched by database struts

To localise any text, we do in general
index.jsp
<!--<span>hello</span>-->
<span><bean:message key="index.hello"/></span>
ApplicationResource_en.properties
index.hello=hello
ApplicationResource_es.properties
index.hello=hola
My problem is how to localise dynamic text like
index.jsp
<span><bean:write "information" property="hello" />
Please suggest ?
You can use bean:message tag instead of bean:write as following
<bean:message bundle= "bundleKey" key= "a.message" />
Bundle is the name of the locale

TFS API DefaultValue for AllowedValues

In my WITD, I have some xml like this in my FIELD tag:
<ALLOWEDVALUES expanditems="true">
<LISTITEM value="Yes" />
<LISTITEM value="No" />
</ALLOWEDVALUES>
<DEFAULT from="value" value="No" />
I can get the allowed values from the API by getting an instance of class FieldDefinition and referencing the AllowedValues property.
How can I get the DEFAULT tag's value from the Api?
You could create a new work item with a work item type that has your field and then check the value of the field on the new work item. You don't need to save the work item to check the field value. It should contain the default value you are after.
There's no API for retrieving default values. Another approach is to parse the value from the WITD XML using WorkItemType.Export Method
var xml = wit.Export(false);

Resources