Written by

Support Leader at BPlus Tecnologia
Question Guilherme Silva · Apr 27, 2018

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

Tomas Vaverka · Apr 27, 2018

Where do you see such text, please? And what version?

0
Guilherme Silva  Apr 27, 2018 to Tomas Vaverka

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.

0
Tomas Vaverka  Apr 30, 2018 to Guilherme Silva

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.

0
Guilherme Silva  May 9, 2018 to Timothy Leavitt

So, this doesn't work when is a dynaform,  because the properties comes from and mdl page (modelclass).

0
Warlin Garcia · Apr 30, 2018

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.

0
Guilherme Silva  May 4, 2018 to Warlin Garcia

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:

0
Timothy Leavitt · Apr 30, 2018

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.

0
Timothy Leavitt  May 9, 2018 to Guilherme Silva

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.

0
Guilherme Silva  May 10, 2018 to Timothy Leavitt

that's it, this resolve my problem. thanks a lot.

0
Peter Cooper · May 10, 2018

Hi Guilherme

Check out the docs - go to documentation and search for Zen Localization

This allows multi-lingual localization 

Peter

0
Vitaliy Serdtsev · May 10, 2018

Localization in Caché DBMS

Simple example:

  1. <FONT COLOR="#000080">Class dc.test Extends %ZEN.Component.page
    </FONT><FONT COLOR="#000000">{
    

    </FONT><FONT COLOR="#000080">Parameter </FONT><FONT COLOR="#000000">DOMAIN = </FONT><FONT COLOR="#800080">"DCTEST"</FONT><FONT COLOR="#000000">;

    </FONT><FONT COLOR="#000080">XData </FONT><FONT COLOR="#000000">Contents [ </FONT><FONT COLOR="#000080">XMLNamespace </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800080">"http://www.intersystems.com/zen" </FONT><FONT COLOR="#000000">] { <</FONT><FONT COLOR="#000080">page </FONT><FONT COLOR="#800000">xmlns</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"http://www.intersystems.com/zen"</FONT><FONT COLOR="#000000">>   <</FONT><FONT COLOR="#000080">radioSet </FONT><FONT COLOR="#800000">id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"lng"     </FONT><FONT COLOR="#800000">label</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"Текущий язык"     </FONT><FONT COLOR="#800000">layout</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"vertical"     </FONT><FONT COLOR="#800000">displayList</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"Португальский,Русский"     </FONT><FONT COLOR="#800000">valueList</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"pt-br,ru"     </FONT><FONT COLOR="#800000">value</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"ru"     </FONT><FONT COLOR="#800000">onchange</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"zenPage.changeLang(zenThis.value);"   </FONT><FONT COLOR="#000000">/>   <</FONT><FONT COLOR="#000080">form</FONT><FONT COLOR="#000000">>     <</FONT><FONT COLOR="#000080">text </FONT><FONT COLOR="#800000">label</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"Описание" </FONT><FONT COLOR="#800000">required</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"true" </FONT><FONT COLOR="#800000">requiredMessage</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"обязательно." </FONT><FONT COLOR="#000000">/>     <</FONT><FONT COLOR="#000080">submit </FONT><FONT COLOR="#800000">caption</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"Сохранить"</FONT><FONT COLOR="#000000">/>   </</FONT><FONT COLOR="#000080">form</FONT><FONT COLOR="#000000">> </</FONT><FONT COLOR="#000080">page</FONT><FONT COLOR="#000000">> }

    </FONT><FONT COLOR="#000080">/// User clicked to change preferred language. ClientMethod </FONT><FONT COLOR="#000000">changeLang(</FONT><FONT COLOR="#ff00ff">lng</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#000080">Language </FONT><FONT COLOR="#000000">= javascript ] {   </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">ok </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#800000">this</FONT><FONT COLOR="#000000">.SrvChangeLang(lng);   self.document.location.reload(); }

    </FONT><FONT COLOR="#000080">/// Change preferred language for this session and page ClassMethod </FONT><FONT COLOR="#000000">SrvChangeLang(</FONT><FONT COLOR="#ff00ff">lng</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#000080">As %Boolean </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">ZenMethod </FONT><FONT COLOR="#000000">] {   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">%session</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Language</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">lng   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">%response</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Language</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">lng   </FONT><FONT COLOR="#0000ff">q $$$YES </FONT><FONT COLOR="#000000">}

    </FONT><FONT COLOR="#000080">Method </FONT><FONT COLOR="#000000">%OnAfterCreatePage() </FONT><FONT COLOR="#000080">As %Status </FONT><FONT COLOR="#000000">{   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">%SetValueById</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"lng"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">%session</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Language</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">Quit $$$OK </FONT><FONT COLOR="#000000">}

    }</FONT>

  2. USER>##class(%MessageDictionary).ExportDomainList("messages_ru.xml","DCTEST","ru")

    Result (messages_ru.xml):

    <?xml <FONT COLOR="#008000">version</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"1.0" encoding</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"UTF-8"</FONT><FONT COLOR="#000000">?> <</FONT><FONT COLOR="#000080">MsgFile </FONT><FONT COLOR="#800000">Language</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"ru"</FONT><FONT COLOR="#000000">>    <</FONT><FONT COLOR="#000080">MsgDomain </FONT><FONT COLOR="#800000">Domain</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"DCTEST"</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"358179803"</FONT><FONT COLOR="#000000">>Текущий язык</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"1805419696"</FONT><FONT COLOR="#000000">>Португальский,Русский</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"2153752096"</FONT><FONT COLOR="#000000">>Описание</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"2835101332"</FONT><FONT COLOR="#000000">>обязательно.</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"3683485237"</FONT><FONT COLOR="#000000">>Сохранить</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>    </</FONT><FONT COLOR="#000080">MsgDomain</FONT><FONT COLOR="#000000">> </</FONT><FONT COLOR="#000080">MsgFile</FONT><FONT COLOR="#000000">></FONT>

  3. messages_pt-br.xml:
    

    <?xml <FONT COLOR="#008000">version</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"1.0" encoding</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"UTF-8"</FONT><FONT COLOR="#000000">?> <</FONT><FONT COLOR="#000080">MsgFile </FONT><FONT COLOR="#800000">Language</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"pt-br"</FONT><FONT COLOR="#000000">>    <</FONT><FONT COLOR="#000080">MsgDomain </FONT><FONT COLOR="#800000">Domain</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"DCTEST"</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"358179803"</FONT><FONT COLOR="#000000">>Idioma atual</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"1805419696"</FONT><FONT COLOR="#000000">>Português,Russo</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"2153752096"</FONT><FONT COLOR="#000000">>Descrição</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"2835101332"</FONT><FONT COLOR="#000000">>é obrigatório.</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>       <</FONT><FONT COLOR="#000080">Message </FONT><FONT COLOR="#800000">Id</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"3683485237"</FONT><FONT COLOR="#000000">>Salvar</</FONT><FONT COLOR="#000080">Message</FONT><FONT COLOR="#000000">>    </</FONT><FONT COLOR="#000080">MsgDomain</FONT><FONT COLOR="#000000">> </</FONT><FONT COLOR="#000080">MsgFile</FONT><FONT COLOR="#000000">></FONT>

    USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%MessageDictionary</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Import</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"messages_pt-br.xml"</FONT><FONT COLOR="#000000">)</FONT>

  4. Profit!
0