; ; @ANO_SCRIPT_NAME string_localize ; @ANO_SCRIPT_VERSION 0.0.1 ; @ANO_SCRIPT_DESCRIPTION Simple string translation example ; ; @ANO_FLAGS_USE_PROTOS [ ] ; @ANO_FLAGS_VAR_NAME_SUBS [ ] ; @ANO_FLAGS_VAR_WARN_UNUSED [ ] ; ; Copyright (c) 2016-2026, Jani Salonen ; All rights reserved. ; ; This example shows how to localize static strings inside Ano script using ; translate{} block. Translate block contains string to be translated with its ; localized versions. ; ; This example can be started as: ; ; $ LC_ALL=fi_FI.UTF-8 ./string_localize ; $ LC_ALL=es_ES.UTF-8 ./string_localize ; ; to make printout either in finnish or spanish. Any other locale or no locale ; at all outputs the default string. ; translate { ; Do not include character set name (that's the UTF-8 part after the ; period) in locale names. ; ; First string is just one block and can be translated as a whole: ; "This is a translation example of how different languages are supported.\n" { fi_FI:"Tämä on käännösesimerkki siitä, miten eri kieliä tuetaan.\n" es_ES:"Este es un ejemplo de traducción de cómo se admiten diferentes idiomas.\n" } ; Ano compiler joins adjacent string parts together if they are same ; type for speeding up printing. Plain string type contains just ; printable characters, where escaped string type has some control ; characters in it. That's why there is two translate parts for second ; print command constructed from three parts given as parameter to ; print. The first two is combined here: ; "My favourite pets are a cat, a dog" { fi_FI:"Lempieläimiäni ovat kissa, koira" es_ES:"Mis animales favoritos son un gato, un perro" } ; Last part of second print command parameter has some control ; characters (linefeed), therefore it is not combined to first two ; parts but it is handled separately: ; " and a hedgehog.\n" { fi_FI:" ja siili.\n" es_ES:" y un erizo.\n" } } main [exit: 0] { ; Localize and print just one plain string: ; print "This is a translation example of how different languages are supported.\n" ; Localize three parts, two plain strings and one with control characters: ; ; First Second Third print "My favourite pets are " . "a cat, " . "a dog" . " and a hedgehog.\n" }