Translated labels in reports

  • 8 January 2019
  • 1 reply
  • 271 views
Translated labels in reports
Userlevel 7
Badge +11

When creating multi-language applications, or applications for companies with customers in different countries, you probably want to translate the report labels too. To translate labels in a report you can retrieve the label transition from a data source, for instance a view. With the Software Factory, you can automatically generate these views with a dynamic concept. In this post we will show you how, by creating a view that returns the column-translations for every language in your project.

To create a view for your report labels, you first need to model a view with an appl_lang_id column as the primary key and the required labels as columns. The name of the view will have a specific prefix (rpt_lbl_), to be able to recognize the report label views in our dynamic concept. Set the creation method of the view to Template.
 


Now we can add the dynamic control procedure to generate the template for all report label views. Add a control procedure, set the assignment type to SQL and the code group to Views.

Then insert the following code:

declare @prefix varchar = 'rpt_lbl_'

-- Insert prog object item for every report label view

insert into prog_object_item
select
@project_id,
@project_vrs_id,
'view_' + t.tab_id,
@control_proc_id,
100,
@control_proc_id,
@control_proc_id
from tab t
where t.project_id = @project_id
and t.project_vrs_id = @project_vrs_id
and t.tab_id like @prefix + '%'
and t.type_of_table = 1 --View
and t.create_view_method = 2 --Template

-- Insert parameters

...

The full code is available in the attachment.

This control procedure will add a template to every program object for views that start with @prefix and creates the required parameters.

Now add a template with the same name as the control procedure to this control procedure, with the following code:

select *
from (values
[open]'[transl]'[close]
) as transl (
[comma][col]
)

After generating the view code will look like this:

select * 
from (values
( 'DE'
,'Land'
,'Stadt'
,'Adresse'
,'€')
,( 'ENG'
,'Country'
,'City'
,'Address'
,'£')
,( 'NL'
,'Land'
,'Stad'
,'Adres'
,'€')
) as transl (
appl_lang_id
,country
,city
,address
,currency
)

Use this view in your report, filter by the required appl_lang_id, drag the fields on your report and off you go!

dc95ab6b-3c94-40c0-8cc4-e01d953280ae.png

 

 


1 reply

I’m looking to implement this logic for my application, one thing I'm not completely sure on however is what strategy is required for this code to function.

If you’re also trying to implement this script, you might also notice that there’s a slight problem on line 1

declare @prefix varchar = 'rpt_lbl_'

This creates a varchar of length 1 which means that later down the line your scripts will filter on
 

where (t.tab_id like (@prefix + '%'))
=>
where (t.tab_id like 'r%')


This might create problems for you later down the line (It did for me), so just make the prefix declaration a varchar(10) or something fitting.
 

Reply