Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

multi-lingual support...

by c (Hermit)
on Jan 04, 2002 at 23:28 UTC ( #136353=perlmeditation: print w/ replies, xml ) Need Help??

a while back, i put together a little script with some serious help from some people i know. its gone through a lot of maturing since i posted it to the monastery. i think it still has a ways to go, however a good deal of people out there have written in appreciation of its existance. the funny thing is, most of them are outside of the english-speaking world.
i'm working at putting in some basic multi-language support. its not much verbage, and i was hoping that some of the community of monks could lend a hand.
my spanish is so/so and my french is mediocre. i'm trying for english/french/german/portuguese/spanish support. there is really no more than 70 words translation, so if you could take a minute to look at what i have below, i'd appreciate it.

oh, there's some perl in there as well, which i dont think i'd mind hearing some comments on as well :-)

The code below is how i am allowing users to select a language. i'm not sure if its the best manner, but i figured creating only one instance of a language hash is better than creating one for each language.

For translation, I know some of the single word translations would be difficult without seeing how they are used in context. after the code, i'm including a full list of in context sentences...

my $language = ""; # your native language # "de" "es" "fr" "pt" "uk" ## create hash of various language specific output my %lang = (); ## set the elected language to lowercase $language = lc($language); ## deutsch if ($language eq "de") { ## español } elsif ($language eq "es") { $lang{flag_req} = "Se requiere al menos una opción."; $lang{run_help} = "Si se necesita ayuda, corre $0 --help"; $lang{no_open} = "No se puede abrir el archivo especificado c +on --list"; $lang{chk_path} = ""; $lang{no_nodes} = ""; $lang{no_snmp} = ""; $lang{no_tftp} = ""; $lang{exp_tftp} = ""; $lang{no_file} = ""; $lang{no_updown} = ""; $lang{version} = ""; $lang{no_log} = ""; $lang{exp_path} = ""; $lang{copy_start} = ""; $lang{no_catos} = ""; $lang{no_depmib} = ""; $lang{cp_success} = ""; $lang{on} = ""; $lang{from} = ""; $lang{to} = ""; $lang{by} = ""; $lang{cp_from} = ""; $lang{cp_to} = ""; $lang{to_nvram} = ""; $lang{cp_nvram} = ""; $lang{from_nvram} = ""; $lang{wr_success} = ""; $lang{rel_success} = ""; $lang{init} = ""; ## français } elsif ($language eq "fr") { ## portugues } elsif ($language eq "pt") { ## english } else { $lang{flag_req} = "Pancho requires some flags to be specified. +"; $lang{run_help} = "Please try running $0 --help"; $lang{no_open} = "Can't open external file specified with --l +ist."; $lang{chk_path} = "Please check the path and ensure file exist +s."; $lang{no_nodes} = "You have not specified a node or a list of +nodes to act upon!"; $lang{no_snmp} = "You have not specified an SNMP community."; $lang{no_tftp} = "You have not specified a tftp server."; $lang{exp_tftp} = "In order to tftp a configuration to a remot +e device"; $lang{no_file} = "you must indicate a specific filename using + -f."; $lang{no_updown} = "You cannot upload and download at the same +time."; $lang{version} = "This is Pancho version"; $lang{no_log} = "Can't open file specified for logging."; $lang{exp_path} = "Please check the path specified."; $lang{copy_start} = "Copying configurations to and from startup- +config"; $lang{no_catos} = "is not possible using the CatOS."; $lang{no_depmib} = "is not possible using deprecated mibs."; $lang{cp_success} = "Successfully copied config to"; $lang{on} = "on"; $lang{from} = "from"; $lang{to} = "to"; $lang{by} = "by"; $lang{cp_from} = "copied from"; $lang{cp_to} = "copied to"; $lang{to_nvram} = "to nvram on"; $lang{cp_nvram} = "copied to nvram on"; $lang{from_nvram} = "from nvram on"; $lang{wr_success} = "Successfully wrote config to memory on"; $lang{rel_success} = "Successfully initialized a reload of"; $lang{init} = "initialization of reload on"; }

Context

"\nPancho requires some flags to be specified.\nPlease try running $0 --help\n\n"

"\nCant open external file specified with --list.\nPlease check the path and ensure file exists.\n\n"

"\nYou have not specified a node or list of nodes to act upon!\n\n"

"\nYou have not specified an SNMP community.\n\n"

"\nYou have not specified a tftp server.\n\n"

"\nIn order to tftp a configuration to a remote device\nyou must indicate a specific filename using -f.\n\n"

"\nYou cannot upload and download at the same time.\n\n"

"\n This is Pancho version $rcs\n\n"

"\nCant open file specified for logging.\nPlease check the path specified.\n\n"

"\nThe following hosts could not be resolved: @failed\n\n"

"\nCopying configurations to and from startup-config\nis not possible using the CatOS.\n\n"

"\nCopying configurations to and from startup-config\nis not possible using deprecated mibs.\n\n"

"\nSuccessfully copied config to $args->{h} from $tftpserver\n\n"

"$format config <$filename> copied from $tftpserver to $args->{h} by $user\n"

"\nSuccessfully copied config to nvram on $args->{h} from $tftpserver\n\n"

"$format config <$filename> copied from $tftpserver to nvram on $args->{h} by $user\n"

"\nSuccessfully copied config to $tftpserver from $args->{h}.\n\n"

"$format config copied to $tftpserver from $args->{h} by $user\n"

"\nSuccessfully copied config to $tftpserver from nvram on $args->{h}.\n\n"

"$format config copied to $tftpserver from nvram on $args->{h} by $user\n"

"\nSuccessfully wrote config to memory on $args->{h}.\n\n"

"$format config copied to nvram on $args->{h} by $user\n"

"\nSuccessfully initialized a reload of $args->{h}.\n\n"

"$format initialization of reload on $args->{h} by $user\n"

humbly -c

Comment on multi-lingual support...
Download Code
(ichimunki) Re: multi-lingual support...
by ichimunki (Priest) on Jan 05, 2002 at 00:11 UTC
    Have you looked at Locale::Maketext, or if you are on a Unix system the GNU gettext utility (which also has a Perl module I think)?

    Of course, this doesn't help you translate the text... there I'm totally useless. :)
Re: multi-lingual support...
by mirod (Canon) on Jan 05, 2002 at 01:13 UTC

    Here is a rough French translation. It is not great as my technical French is getting quite poor as I use mostly English these days ;--( and as I don't use any French software.

    As a general comment I am afraid you are being a little too clever here. The order of words in a sentence vary between languages, and it is very difficult, if not right down impossible, to generate sentences from bits and pieces like you do. Usually if you want your software to be easily ported to other languages each message (or at least each sentence) has to be a separate string. A common trickis to use sprintf in order not to depend on the original English order:

    "$format config copied to $tftpserver from $args->{h} by $user\n"

    becomes:

    sprintf "config copied to %s from %s by %s\n", $tftpserver, $args->{h}, $user;

    (note that $args->{h} will not be interpolated properly in the string by the way)

    And in French:

    sprintf "configuration de %s copiée sur %s par %s\n", $tftpserver, $args->{h}, $user;

    Note that if you want to be able to change the order of parameters you will need to add yet an other indirection layer, for example the message could be stored as "configuration de $par{server} copiée sur $par{target} par $par{user}\n" and the output being done by a sub that gets passed the parameters as a hash.

    Anyway, here is the translation, which will certainly be corrected by other Mongueurs.

    $lang{flag_req} = "Pancho: Options manquantes" $lang{run_help} = "Entrer $0 --help"; $lang{no_open} = "Impossible d'ouvrir le fichier spé +cifié par --li"; $lang{chk_path} = "Veuilliez vérifier le chemin et l' +existence du fichier"; # I don't know if 'noeud' is the proper translation for 'node +' here $lang{no_nodes} = "Vous n'avez pas spécifié un noeud +ou une liste de noeuds cible"; $lang{no_snmp} = "Vous n'avez pas spécifié une commu +nauté SNMP."; $lang{no_tftp} = "Vous n'avez pas spécifié un serveu +r tftp."; # The adjective comes after the noum in French, so you can't +have a hanging 'remote' $lang{exp_tftp} = "Pour tftp une configuration"; $lang{no_file} = "Vous devez spécifier un nom de fic +hier avec l'option -f"; # 'telecharger' means both upload and downlod in French :--( $lang{no_updown} = "Impossible d'uploader et de telech +arger en meme temps"; $lang{version} = "Pancho version"; $lang{no_log} = "Impossible d'ouvrir le fichier log +"; $lang{exp_path} = "Veuillez vérifier le chemin"; # we're starting to hit problems here, the syntax does not ma +tch $lang{copy_start} = "Copie de la configuration de et ve +rs startup-c"; $lang{no_catos} = "impossible avec CatOS."; $lang{no_depmib} = "impossible avec mibs (obsoléte)."; + # it should be a e` (&egrave; here) $lang{cp_success} = "Copie effectuée vers"; # this rarely works $lang{on} = "sur"; $lang{from} = "de"; $lang{to} = "vers"; $lang{by} = "par"; $lang{cp_from} = "copié de"; $lang{cp_to} = "copié vers"; $lang{to_nvram} = "vers nvram sur"; $lang{cp_nvram} = "copié vers nvram sur"; $lang{from_nvram} = "de nvram sur"; $lang{wr_success} = "Configuration chargée en memoire s +ur"; # it's hard to fit the originalwording in a French sentence $lang{rel_success} = "Rechargement des parametres de"; $lang{init} = "initialisation du rechargement sur +";
      Note that if you want to be able to change the order of parameters you will need to add yet an other indirection layer...

      update: Okay... I should check docs less recent then the latest development version. Read this as "you won't have to in the next version of perl".

      Actually, you won't. To quote the sprintf docs:

      Perl supports parameter ordering, in other words, fetching the parameters in some explicitly speci fied "random" ordering as opposed to the default implicit sequential ordering. The syntax is, instead of the "%" and "*", to use "%"digits"$" and "*"digits"$", where the digits is the wanted index, from one upwards. For example:
      printf "%2\$d %1\$d\n", 12, 34; # will print "34 12\n" printf "%*2\$d\n", 12, 3; # will print " 12\n"
      (... more stuff on this topic omitted ...)
Re: multi-lingual support...
by belden (Friar) on Jan 05, 2002 at 08:51 UTC
    Spanish:

    I'm missing a few accents so have put capital letters midway through strings to indicate that they should be accented. I also start sentences with ! which should actually be inverted.

    $lang{flag_req} = "Pancho: Requiere una opción o mAs."; $lang{run_help} = "Tecla $0 --help"; $lang{no_open} = "No se puede abrir el archivo especifica +do por --list."; $lang{chk_path} = "Por favor de verificar que el archivo llama +do sI existe en su path"; $lang{no_nodes} = "!No ha llamado una noda o una tabla de noda +s para esta acción!"; $lang{no_snmp} = "No ha llamado una comunidad SNMP."; $lang{no_tftp} = "No ha llamdo un servidor de tftp."; $lang{exp_tftp} = "Para mandar a un dispositivo remoto una con +figuración por tftp"; $lang{no_file} = "hay que indicar a un fichero especIfico"; $lang{no_updown} = "No se puede mandar y recibir al mismo tiemp +o."; $lang{version} = "Pancho versión"; $lang{no_log} = "No podrIa arrancar al fichero llamado"; $lang{exp_path} = "Por favor de verificar el path llamado."; $lang{copy_start} = "No se puede copiar configuraciones de start +up-config al mismo tiempo que copie configuraciones a startup-config" +; $lang{no_catos} = "cuando se usa CatOS."; $lang{no_depmib} = "cuando se usa el mibs (desaprobado)"; $lang{cp_success} = "Config copiado a"; $lang{on} = "en"; $lang{from} = "de"; $lang{to} = "a"; $lang{by} = "por"; $lang{cp_from} = "copiado de"; $lang{cp_to} = "copiado a"; $lang{to_nvram} = "al nvram en"; $lang{cp_nvram} = "copiado al nvram en"; $lang{from_nvram} = "copiado de nvram en"; $lang{wr_success} = "Configuración guardó en"; $lang{rel_success} = "Empezó el proceso de recargar"; $lang{init} = "empezar del proceso de recargar en";
    blyman
    setenv EXINIT 'set noai ts=2'
Re: multi-lingual support...
by gri6507 (Deacon) on Jan 05, 2002 at 11:44 UTC
    I have done some UTF8 work before where we needed to have English/Chinese capabilities with possibilities for expansions. The approach we took was to create a seperate file of messages for each language written in their native encoding orgnaized by (in our case) number. I wonder if this approach would be easiest to code and most flexible in regard to expansions.

    btw, if you would like, I can translate those sentences for you into russian

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://136353]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2014-12-28 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls