Next: Extract marked strings in your code, Previous: Pure Scheme internationalization with po-lib, Up: Pure Scheme internationalization with po-lib [Contents][Index]
Let us look at an example:
(define (main) "Say the line." (display "Hello, world!") (newline))
In this example, you may want to translate the greeting message in the
user’s language. Import the (po-lib) module, and mark the line:
(import (po-lib)) (define (main) "Say the line." (display (gettext "Hello, world!")) (newline))
Please note that if you are running your code on the Hoot platform, you will need to provide additional webassembly imports. See How to use po-lib on Hoot.
Translate msgid into the current locale. The behavior can be modified with the options syntax, according to the following example:
(gettext "This is the message to print." (domain "my library") (context "disambiguation string") (plural "These are the ~a messages to print." n-messages) (comments "Dear translators, I address this message to you \ regarding the example translation.") (source "example-file.scm" 42) (range minimum-possible-n-messages maximum-possible-n-messages) (extra-flags "scheme-format"))
domainIf you are defining a library, you most likely don’t want your translations to clash with those of a dependent library. In order to prevent that from happening, you should make sure to use a domain for your internationalized code. See Solving Ambiguities in GNU ’gettext’ utilities.
contextEnglish can use the same word to mean two different things, where other languages will want to use different strings. The context is not visible to the user, but it will help choose the correct translation. See Using contexts for solving ambiguities in GNU ‘gettext’ utilities.
pluralIf the message can be singular or plural depending on a run-time value (here, n-messages), then the correct translation should be picked according to the plural forms for the current language. The first argument is the alternative plural form in English, and the second argument is the argument of the thing marked plural. See Additional functions for plural forms in GNU ’gettext’ utilities.
commentsIt might be a good idea to indicate to the translator some information about how the message will be used. See The Format of PO Files in GNU ’gettext’ utilities.
sourceYou may want to indicate the source location as a filename and line number, but you maybe should only do that as a macro expansion side-effect.
rangeextra-flagsBy default, the plural case can handle any number for the plural argument. However, in certain cases, it is known that the plural argument may be constrained into a range, which can help the translators. Other flags may also be passed. See The Format of PO Files in GNU ’gettext’ utilities.
Sometimes you do not want to actually perform the translation, but still mark the string so that it can be translated.
Return msgid. The options are the same as those for gettext, but the run-time plural argument is discarded at the syntax level.