Example: Create a Report Design With Dynamic Translation Based on Preferred Locale
This example illustrates how to use scripts to dynamically translate label text on custom reports based on the worker's preferred locale instead of the language preference of the user who prints the report.
Your HR department wants you to create a report design for a new hire letter that prints a custom report with the translated text based on the worker's locale preference. You need to create a custom report in Workday and run the report for the worker Logan McNeil, whose account has the preferred locale set to French (Canada).
- Create a report design for a new hire letter. See Example: Create a Report Design for a Letter.
- Configure the preferred locale for the new hire letter report:
- Sign in to your Workday GMS tenant.
- Access theEdit Custom Reporttask.
- From theReport Nameprompt, selectMy New Hire Report.
- On theColumnstab, add a row and specify these values:Business ObjectFieldColumn Heading OverrideColumn Heading Override XML AliasEmployeePreferred LocaleLocaleLocale
- ClickOKandDone.
- Configure the locale preferences of the worker Logan McNeil:
- Sign in to the Workday GMS tenant as Logan McNeil:lmcneil.
- In , set thePreferred Localeprompt toFrançais (Canada)-fr_CA.
- ClickOKandDone.
- Sign out of this account.
- Open Report Designer in Workday Studio.
- Create a report project namedTranslation With Scripts.
- Move or copy theNew Hire Letter.rptdesignreport file you created earlier and place it in theTranslation With Scriptsproject.
- Create a Workday data source and download some sample data:
- Create a newWorkday Report Data SourcenamedNew Hire Letter Data Source.
- Download the report description for theMy New Hire Letter Reportcustom report from Workday.
- Download sample report data from Workday and name the fileNew Hire Letter.xml
- Select and specifyWorkerinstances to include in the report, then clickOK.
- ClickDownloadandTest Connection.
- When the Report Designer displays aSuccessmessage, clickOKandFinish.
- Create a new data set with these values:OptionValueData Source SelectionNew Hire Letter Data SourceData Set TypeWorkday Primary Report Data SetData Set NameEmployees
- Add this text to the resource file:Dear=DearCongratulations=Congratulations on joining our team. We are excited to have you!Terms=Your employment with our Company includes the following agreed upon terms:Date_of_Hire=Date of Hire:Business_Title=Business Title:Manager_Name=Manager Name:Organization=Organization:Location=Location:Amount=Base Pay Amount:Disclaimer=Please be advised that your employment with the Company will be "at will", which means that either you or the Company may terminate your employment at any time, for any reason or no reason, with or without notice. There is no promise by the Company that your employment will continue for a set period of time or that your employment will be terminated only under peculiar circumstances.Sincerely=Sincerely,
- Name the resource filetranslation.properties.
- Add tis text to the resource file:Dear=Cher(ère)Congratulations=Félicitations pour avoir rejoint notre équipe. Nous sommes ravis de vous compter parmi nous!Terms=Votre emploi au sein de notre entreprise est soumis aux conditions suivantes :Date_of_Hire=Date d'embauche :Business_Title=Titre professionnel :Manager_Name=Nom du gestionnaire :Organization=Organisation :Location=Emplacement :Amount=Montant du salaire de base :Disclaimer=Veuillez noter que votre emploi au sein de la Société sera « à volonté », ce qui signifie que vous ou la Société pouvez mettre fin à votre emploi à tout moment, pour quelque raison que ce soit ou sans raison, avec ou sans préavis. La Société ne promet aucunement que votre emploi se poursuivra pendant une période de temps déterminée ou que votre emploi prendra fin uniquement dans des circonstances particulières.Sincerely=Sincèrement,
- Name the resource filetranslations_fr_CA.properties.
- Associate the resource files with the report design file:
- In theProperty Editor - Reportview, select theResourcestab.
- ClickAdd File...and add these files to theProperties Fileslist:
- translations.properties
- translations_fr_CA.properties
- Add theonCreatescript for the translatable text for each label report item:
- In theLayoutview of your design, click theDearlabel.
- From theScripttab, selectonCreatefrom theScriptslist.
- In the text pane, add this script for the label:importPackage(Packages.java.util); if(row["Locale"]=="fr_CA") { var lc = new Locale("fr_CA"); this.text = reportContext.getMessage("Dear", lc);}
- Repeat steps a. through c. for each label that requires dynamic translation.
- Save your work.You can check whether there's a script associated with a label report item in theAdvancedtab inProperty Editor.
- To access the preferred locale for each worker at runtime, add a table to the layout:
- In theOutlineview, right-click theBodynode, then selectInsert Element.
- Double-click theTableelement and configure these values:Number of columns1Number of details1Number of detailsEmployeesYou only need the detail row of your table. To delete the header and footer rows, right-click in the row guide cell, then selectDelete.
- Move the existing report items from theBodynode in theOutlineview toDetail Rowin the table:
- ExpandDetail Rowdown to theCelllevel.
- Select the nodes below theBodynode that you want to move by pressing theShiftkey, followed by theImagenode, and the lastDatanode.
- Right-click and selectCut, then right-click on the detail rowCellnode and selectPaste.
- Save and preview your design.
When you print the
My New Hire Letter Report
for Logan McNeil
, the onCreate
scripts translate the label text in the report into French, using the key values in the translations_fr_CA.properties
file. Deploy your design to Workday for use as business form layout.