Change language - Required
Hi,
someone knows how to change the "required" to portuguese.
it's a property(Required) on persistence.
i want to change from "required" to "obrigatório"

Comments
Where do you see such text, please? And what version?
this is the property :
Property Descricao As %String [ Required ];
and the version is Caché 2014.1
this occours when you try to persist an empty property in a zen page.
Is it your own Zen page? If yes, could you post the code here? The text comes from the page itself so I would like to see where the text comes from, what component is used etc.
So, this doesn't work when is a dynaform, because the properties comes from and mdl page (modelclass).
These are compiler instructions. Not sure if the instructions change based on the cache installation language (e.g. English vs. Portuguese). You can change the language for Studio based on your locale but that's only for menus and such.
not about the instructions, the question is to change the language of the alert. for example:

i can change the message "this form...." to whatever i want, but the message and the "required." don't change to pt-br, even the SessionLanguage is pt-br.
for example, when i have a validation on Persistent class, the message is the following:
This can be done with the requiredMessage property of %ZEN.Component.control. There are two ways to accomplish this:
1. Just add the requiredMessage attribute
Class DC.Demo.ZenLocalization Extends %ZEN.Component.page
{
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen">
<form>
<text label="Descrição" required="true" requiredMessage="obrigatório." />
<submit caption="Enviar" />
</form>
</page>
}
}
Problem is, you'd need to do that in a lot of different places. Instead, you could...
2. Use custom components that subclass built-in control types.
Sample component:
Class DC.Demo.Component.text Extends %ZEN.Component.text [ System = 3 ]
{
/// Feel free to customize this.
Parameter NAMESPACE = "https://community.intersystems.com/post/change-language-required";
/// Value displayed in alert box by the form <method>validate</method>
/// method when this control is required and does not have a value.<br>
/// This is a localized value.
Property requiredMessage As %ZEN.Datatype.caption [ InitialExpression = "obrigatório." ];
}Sample page using component:
Class DC.Demo.ZenLocalization Extends %ZEN.Component.page
{
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen" xmlns:custom="https://community.intersystems.com/post/change-language-required">
<form>
<custom:text label="Descrição" required="true" />
<submit caption="Enviar" />
</form>
</page>
}
}I was hoping there would be a way to use Zen's localization features to do this, but it seems like that isn't an option, unfortunately;"required." is hard-coded as the InitialExpression for requiredMessage in %ZEN.Component.control, and may only be localized within a page using the component if a non-default value is specified.
With a dynaForm, this would look like:
Class DC.Demo.ZenLocalizationModel Extends %ZEN.DataModel.ObjectDataModel
{
Property Descrição As %String(ZENATTRS = "requiredMessage:obrigatório.") [ Required ];
}
And:
Class DC.Demo.ZenLocalization Extends %ZEN.Component.page
{
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen">
<dataController id="myController" modelClass="DC.Demo.ZenLocalizationModel" />
<dynaForm controllerId="myController" injectControls="before">
<submit caption="Enviar" />
</dynaForm>
</page>
}
}For more information on how to customize data model behavior with property parameters, see the class reference for %ZEN.DataModel.objectModelParameters.
that's it, this resolve my problem. thanks a lot.
Glad to help!
Hi Guilherme
Check out the docs - go to documentation and search for Zen Localization
This allows multi-lingual localization
Peter
Simple example:
-
Class dc.test Extends %ZEN.Component.page { Parameter DOMAIN = "DCTEST"; XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ] { <page xmlns="http://www.intersystems.com/zen"> <radioSet id="lng" label="Текущий язык" layout="vertical" displayList="Португальский,Русский" valueList="pt-br,ru" value="ru" onchange="zenPage.changeLang(zenThis.value);" /> <form> <text label="Описание" required="true" requiredMessage="обязательно." /> <submit caption="Сохранить"/> </form> </page> } /// User clicked to change preferred language. ClientMethod changeLang(lng) [ Language = javascript ] { var ok = this.SrvChangeLang(lng); self.document.location.reload(); } /// Change preferred language for this session and page ClassMethod SrvChangeLang(lng) As %Boolean [ ZenMethod ] { s %session.Language=lng s %response.Language=lng q $$$YES } Method %OnAfterCreatePage() As %Status { d ..%SetValueById("lng",%session.Language) Quit $$$OK } } -
USER>d ##class(%MessageDictionary).ExportDomainList("messages_ru.xml","DCTEST","ru") Result (messages_ru.xml): <?xml version="1.0" encoding="UTF-8"?> <MsgFile Language="ru"> <MsgDomain Domain="DCTEST"> <Message Id="358179803">Текущий язык</Message> <Message Id="1805419696">Португальский,Русский</Message> <Message Id="2153752096">Описание</Message> <Message Id="2835101332">обязательно.</Message> <Message Id="3683485237">Сохранить</Message> </MsgDomain> </MsgFile> -
messages_pt-br.xml: <?xml version="1.0" encoding="UTF-8"?> <MsgFile Language="pt-br"> <MsgDomain Domain="DCTEST"> <Message Id="358179803">Idioma atual</Message> <Message Id="1805419696">Português,Russo</Message> <Message Id="2153752096">Descrição</Message> <Message Id="2835101332">é obrigatório.</Message> <Message Id="3683485237">Salvar</Message> </MsgDomain> </MsgFile> USER>d ##class(%MessageDictionary).Import("messages_pt-br.xml") - Profit!