http://qs321.pair.com?node_id=108042

When shadox posted his JPEG Files ReSize with output in Spanish, and bladx replied with "Converting the Spanish text to English, (for easier readability for English-speaking persons. Or perhaps, the english equivilents maybe?) :)", that got me thinking.

After spending most of the weekend working on maintaining my computer, I finally got around to trying this.

Obviously, a Perl program can use the native or normal multi-language features of the platform. In Win32, that means using a "resource" file, and since Perl doesn't use PE (COFF) files for the executable, it would have to be an additional file. And you would need tools for making it etc. You could have some kind of external file listing all the strings per language, but no matter what format that file's in, you need to replace all the strings in the program with ID values. That can make things less-than-readable, especially for simple scripts that have lots of on-the-fly output (as opposed to labels on widgets loaded from a database).

So, I think it will help if all possible forms are supplied in the program's text, near where it is used. Ideally, it could be done right where the string would have gone.

Here is my proof-of-concept:

use strict; use warnings; use LangString; my $s1= new LangString { English => "Error opening directory", Spanish => "Error abriendo directorio" }; print "My string is $s1\n"; $LangString::Language= 'Spanish'; print "My string is $s1\n";
I wonder if anyone can further improve on the syntax and usability?

Here is the code:

use strict; use warnings; package LangString; our $Language= 'English'; use overload '""' => \&string; sub new { my $class= shift; my $self= shift; bless $self, $class; return $self; } sub string { my $self= shift; return $$self{$Language}; } 1;
It's simplistic, because it's just a concept. In a full implementation, the default would automatically obtain the language from the OS, and strings would be checked for absense and use an inheritance mechanism (e.g. British and American only specified when there are differences, but English specified when it works for both) and other error checking.

—John


Summary of commentary and additional thoughts: