Internationalisation perl gotcha

One of the issues to look out for when applying gettext to perl programs is variable substitution. For example:

  print "My name is $name\\n"

Should not be internationalised as:

  print gettext("My name is $name\\n");

Because the variable substitution for $name occurs before the call to gettext - hence gettext would get the text including the value of the variable $name, and would require a separate translation for every value of $name.

There are number of alternatives to this, printf or string concatenation. These work for many situations, but can present a problem when there are multiple variables being substituted and the order of the variables is different in different locales.

Comments:

Post a Comment:
Comments are closed for this entry.
About

Darryl Gove is a senior engineer in the Solaris Studio team, working on optimising applications and benchmarks for current and future processors. He is also the author of the books:
Multicore Application Programming
Solaris Application Programming
The Developer's Edge
Free Download

Search

Categories
Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today
Bookmarks
The Developer's Edge
Solaris Application Programming
Publications
Webcasts
Presentations
OpenSPARC Book
Multicore Application Programming
Docs