Skip to content

Commit

Permalink
Merge pull request #26 from intersystems-ru/translate
Browse files Browse the repository at this point in the history
Translate
  • Loading branch information
eduard93 authored Apr 14, 2017
2 parents dc52f24 + 2ef797d commit 01887d6
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Form.inc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
#; Test if object variable is defined and not Null
#define isDefObject(%obj) ($Data(%obj)#2&&$IsObject(%obj))
#define domain "RESTFORMS"
#define domainq """"_$$$domain_""""
]]></Routine>
</Export>
27 changes: 27 additions & 0 deletions Form/Generators.cls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,32 @@ Validate FORMORDERBY parameter value if present</Description>
quit sc
]]></Implementation>
</Method>

<Method name="translate">
<Description>
Fill ^CacheMsg global for further translation</Description>
<Internal>1</Internal>
<ClassMethod>1</ClassMethod>
<CodeMode>objectgenerator</CodeMode>
<GenerateAfter>generateMetadata</GenerateAfter>
<Implementation><![CDATA[
#Include Form
#dim sc As %Status = $$$OK
set className = %compiledclass.Name
set formNameKey = %class.Parameters.FindObjectId(className _ "||" _ $$$formNameParam)
set formName = $get(%parameter($$$formNameParam))
return:(($$$skipClasses[className)||(formName="")||(formNameKey="")) sc
#dim prop As %Dictionary.PropertyDefinition
for i = 1:1:%class.Properties.Count() {
set prop = %class.Properties.GetAt(i)
set displayName = prop.Parameters.GetAt($$$propDisplayNameParam)
if prop.Internal || prop.Calculated || prop.ReadOnly || prop.Private || prop.Identity || prop.MultiDimensional || displayName = "" continue
do ##class(Form.Util.Translate).insert(displayName)
}
quit $$$OK
]]></Implementation>
</Method>
</Class>
</Export>
1 change: 1 addition & 0 deletions Form/Property.cls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ w ##class(Form.Property).getPropertyDisplayName("Form.Test.Simple", "text")</Des
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set displayName = ..getPropertyParam(className, name, $$$propDisplayNameParam)
set displayName = ##class(Form.Util.Translate).get(displayName)
set:displayName="" displayName = name
return displayName
]]></Implementation>
Expand Down
4 changes: 4 additions & 0 deletions Form/REST/Abstract.cls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<Super>%CSP.REST</Super>
<TimeCreated>64090,76470.397537</TimeCreated>

<Parameter name="CONTENTTYPE">
<Default>application/json</Default>
</Parameter>

<Parameter name="UseSession">
<Type>Integer</Type>
<Default>1</Default>
Expand Down
45 changes: 45 additions & 0 deletions Form/Util/Translate.cls.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="Form.Util.Translate">
<Description>
Support for metadata translation </Description>
<IncludeCode>Form</IncludeCode>
<TimeCreated>64386,54065.171182</TimeCreated>

<Method name="get">
<Description>
Get translated value of a text
w ##class(Form.Util.Translate).get()</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>text:%String</FormalSpec>
<Implementation><![CDATA[
set domain = $$$domain
set language=""
if $isObject($g(%request)) {
set language=$$MatchLanguage^%occMessages(%request.GetCgiEnv("HTTP_ACCEPT_LANGUAGE"))
}
set:language="" language = $s($mvv(58)="":"en",1:$mvv(58))
set id = $zcrc(text, 7)
set text = $$$GetAppMessage(language, domain, id, text)
set text = $zcvt(text, "O", "UTF8")
quit text
]]></Implementation>
</Method>

<Method name="insert">
<Description>
Add text to ^CacheMsg
do ##class(Form.Util.Translate).Insert()</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>text</FormalSpec>
<Implementation><![CDATA[
set text = $$$quote(text)
set domain = $$$domainq
set a = $$macroText^%occMessages($lb(text, domain))
]]></Implementation>
</Method>
</Class>
</Export>

0 comments on commit 01887d6

Please sign in to comment.