String Constants: GUI Internationalization
This library provides the facility for multiple languages in DrRacket’s GUI.
1 Using String Constants
(require string-constants) | package: string-constants-lib |
syntax
(string-constant name)
syntax
(string-constants name)
syntax
procedure
(dynamic-string-constant name) → string?
name : string-constant?
procedure
(dynamic-string-constants name) → (listof string?)
name : string-constant?
procedure
(string-constant? v) → boolean?
v : any/c
procedure
(dynamic-string-constant-in-current-language? key) → boolean?
key : string-constant?
procedure
v : any/c
procedure
(call-with-current-language sc-language thunk) → any sc-language : string-constant-langauge? thunk : (-> any)
This function is designed to facilitate testing of libraries that use string constants, so they can work regardless of the user’s language setting.
syntax
syntax
procedure
(set-language-pref lang) → void?
lang : string?
2 Adding String Constants
To add string constants to DrRacket, see the file "private/english-string-constants.rkt" and the other string constants files in the "private" directory. (Some string constants files that have a less permissive license are also available on the pkg server in the string-constants-lib-lgpl pkg.)
Each file has the same format. They are each modules in the string-constants/private/string-constant-lang language. The body of each module is a finite mapping table that gives the mapping from the symbolic name of a string constant to its translation in the appropriate language. Multiple string constants that appear together are implicitly concatenated.
The "english-string-constants" is considered the master file; string constants will be set there and translated into each of the other language files. In addition, the "english-string-constants.rkt" file should contain hints about the context of the strings whose symbol name might not be clear.
3 Language Environment Variables
If either of these environment variables are set, DrRacket shows you, during startup, which string constants are not yet defined for each language.
You can also specify which languages you are interested in. If either environment variable is bound to a symbol (as interpreted by read) you see only the corresponding language’s messages. If either one is bound to a list of symbols (again, as interpreted by read) you see the messages for all the languages in the list. If either is bound to anything else, you see all of the languages.
The PLTSTRINGCONSTANTS environment variable takes precedence over the STRINGCONSTANTS environment variable.
The PLTSTRINGCONSTANTSLANG controls the language choice, overriding the default saved in the preferences file. If it is not set to one of the languages in the result of all-languages, it is ignored.
4 How To Translate DrRacket’s String Constants in Your Language
This is a short hands-on guide how to translate the strings used within DrRacket’s GUI. It is targeted at people willing to translate the interface who may not know all ins and outs of Racket.
4.1 Introduction
DrRacket is a is a development environment for the many languages you can use via Racket — the language developers’ language. The interface is already translated in more than a dozen languages, some of which are more actively maintained than others.
If you are interested how much time and effort you will need to invest — roughly 3 afternoons.
Here are the steps:
4.2 Preparation
Clone the https://github.com/racket/string-constants repo. This is where you will work, translate, and finally submit the translation via a pull request.
Go to the string-constants-lib/string-constants/private directory — it contains all the translations. Start with copying the file english-string-constants.rkt to yourlanguage-string-constants.rkt.
English is the master file containing the originals of the strings. Therefore, start with a copy of that. Note that if you continue to update and maintain your translation English will be the file you will sync with.
(require (prefix-in english: "private/english-string-constants.rkt") … (prefix-in yourlanguage: "private/yourlanguage-string-constants.rkt"))
(define built-in-string-constant-sets (list (make-sc 'english english:string-constants #f) … (make-sc 'yourlanguage yourlanguage:string-constants #f)))
And with that you are done with the initial work — you have created a template for your language (still filled in with the English originals) and you have told Racket to use it. We are off to the races and all we need to do is fill in the translations.
4.3 Translation
Open yourlanguage-string-constants.rkt in your favorite text editor. It has a fairly trivial structure: it is basically a map — a long list of key-value pairs. The key is the identifier of the string — how Racket source code is going to refer to the message. Do not change these. The value is the translation. As you started with the English version — you have all the comments and the formatting. I highly recommend keeping these in place because they are very helpful when you need to update the translations.
(module english-string-constants "string-constant-lang.rkt" …)
(module yourlanguage-string-constants "string-constant-lang.rkt" …)
The second thing is to add some metadata to your file. You can use standard comments in the file – either prefix a line with double semicolon ;; or comment out a block of text via #| commented block |#.
In that part of the file put some basic data — like your name, which version of the private/english-string-constants.rkt file you are syncing with. This is also the place to put out conventions for the translation such as specific terms, style etc. I would also recommend spelling out the license you want to use. Note that for anything that is to be distributed with Racket, the maintainers will be more likely to accept it if you use the strategy below:
In the Bulgarian translation I have explicitly pointed out:
;; This file is distributed under the same terms as Racket
Currently translations are double licensed — under the Apache 2.0 license and the MIT license.
All the translated strings are quoted by double quotes. So if you need to put " in the translation you would need to quote it like \". However I recommend you use proper quotation marks for your language.
A new line is represented by \n. ~a is substituted with whatever parameter is given to the string template.
(install-plt-error-downloading "There was an error when downloading the" " .plt file.\n\nDetails:\n")
is the same as:
(install-plt-error-downloading "There was an error when downloading the .plt file.\n\nDetails:\n")
You can use this to wrap where you want in case strings get too long. Just make sure you do not have a dangling space at the end of a string portion. So using the current example:
(install-plt-error-downloading "There was an error when downloading the " " plt file.\n\nDetails:\n")
Note how the space is at the end of the first line. This will cause breakage. There are ways around this but it is better to not need them.
Once you finish the translation – create a pull request to the https://github.com/racket/string-constants repo. If you are interested in how the whole infrastructure of translation works in DrRacket – have a look at the documentation.