Commit a6400fd9 authored by Daniel Kochmański's avatar Daniel Kochmański
Browse files

cosmetic: multiple language corrections



Thanks to Robert Strandh
Signed-off-by: Daniel Kochmański's avatarDaniel Kochmański <daniel@turtleware.eu>
parent c19957ac
......@@ -2,13 +2,13 @@
* Introduction
=TRANSLATE= is a thin abstraction layer over the ordinary strings
which allows creation of a seamless translation for your
project. Code is written in a plain Common Lisp without any
dependencies. System definition is provided in =ASD= format,
which allows the creation of a seamless translation for your
project. The code is written in a plain Common Lisp without any
dependencies. A system definition is provided in =ASD= format,
although =ASDF= isn't required to run this software.
Library is licensed under =LLGPLv2=, what means that it may be used
in any project for any purpose although any significant
This library is licensed under =LLGPLv2=, which means that it may be
used in any project for any purpose although any significant
modifications to the library should be published. It doesn't impose
it's license on software depending on it.
......@@ -16,16 +16,17 @@
=MAKE-BUTTON= and =MAKE-LABEL=. The following sample code convention
is used:
- lines predated with ==> indicate *reader* input
- lines preceded with ==> indicate *reader* input
- all other lines represent *printer* output
* Description
** Basic usage
Library pollutes =*READTABLE*= with dispatch macro character =#t=,
where "t" is abbreviation of "translate". User instead of writing
bare strings in his/her application, predates them with =#t=:
The library pollutes =*READTABLE*= with dispatch macro character
=#t=, where "t" is abbreviation of "translate". Instead of writing
ordinary constant strings in his/her application, the user instead
precedes them with =#t=:
#+BEGIN_SRC common-lisp
==> #t"dum dum, piję rum"
......@@ -33,10 +34,10 @@
#+END_SRC
If =TRANSLATE:*LANGUAGE*= is bound to =NIL= and
=TRANSLATE:*RESOLUTION-TIME*= to =:LOAD-TIME=, then =#t="hello" will
resolve to the string "hello" and translation will have no
=TRANSLATE:*RESOLUTION-TIME*= to =:LOAD-TIME=, then =#t="hello"
will resolve to the string "hello" and the translation will have no
effect. It is convenient, because programmer can put =#t="strings"
for the future translation with no functional consequences at the
for the future translation with no functional consequences at
run-time while keeping application innards visually separated from
the messages meant to be presented to user.
......@@ -46,7 +47,7 @@
#<button "hello">
#+END_SRC
Binding =TRANSLATE:*LANGUAGE*= to non-NIL value enables string
Binding =TRANSLATE:*LANGUAGE*= toa non-NIL value enables string
translation. If no translation exists it will be temporarily
translated to the same value enclosed in a curly brackets:
......@@ -63,27 +64,27 @@
#<label "{Leave the grid}">
#+END_SRC
Using not translated string will cause a warning at the resolution
time and string will be added to the special list of phrases not
yet translated (which may be evaluated for the future processing,
like adding the missing translations). If a language put in the
=TRANSLATE:*LANGUAGE*= isn't defined yet, =CERROR= will be
signalled with a restart allowing language creation.
Using a string that has not been translated will cause a warning at
resolution time and string will be added to the special list of
phrases not yet translated (which may be evaluated for future
processing, like adding the missing translations). If a language
put in the =TRANSLATE:*LANGUAGE*= isn't defined yet, =CERROR= will
be signaled with a restart allowing language creation.
To distinguish dictionaries predicate =EQL= is used and phrases are
distinguished using predicate =EQUAL=, so the most convenient is
using symbols as the language designators. It also implies, that
phrases meant for translation are case sensitive.
To distinguish dictionaries, th predicate =EQL= is used and phrases
are distinguished using the predicate =EQUAL=, so the most
convenient is using symbols as the language designators. It also
implies, that phrases meant for translation are case sensitive.
** Adding translation
To add translations two interfaces are
provided. =ADD-SINGLE-TRANSLATION= function takes three arguments,
where the first is the language for which we provide translation,
the second is a translated phrase and the third is an actual
To add translations, two interfaces are provided. The
=ADD-SINGLE-TRANSLATION= function takes three arguments, where the
first is the language for which we provide translation, the second
is a translated phrase and the third is an actual
translation. Phrase type must be a string, but the translation
might be any kind of object (although it is advised to use strings
user is free to shoot himself in the foot by abusing the
might be any kind of object (although it is advised to use strings,
the user is free to shoot himself in the foot by abusing the
translation mechanism).
#+BEGIN_SRC lisp
......@@ -105,10 +106,10 @@
#+END_SRC
=ADD-TRANSLATIONS= is a simple wrapper around
=ADD-SINGLE-TRANSLATION= that allows translating multiple phrases
in one form. The first argument is once again the translation
language, while all further arguments are alternately phrases and
translations.
=ADD-SINGLE-TRANSLATION= that allows the translation of multiple
phrases in one form. The first argument is once again the
translation language, while all further arguments are alternately
phrases and translations.
#+BEGIN_SRC lisp
==> (translate:add-translations 'pl
......@@ -140,16 +141,16 @@
Generally it is advised to use symbolic and meaningful names for
phrases to be translated, not the final phrases written in English.
Providing "translation-tags" of concise form is easier to
comprehend for people, who will translate the application.
comprehend for people who will translate the application.
** Interactive fixing of the missing phrases
Loading the code is enough to catch all not yet translated phrases
for the active language (bound to =TRANSLATE:*LANGUAGE*=) if
resolution is performed at load time. Otherwise not translated
resolution is performed at load time. Otherwise, an untranslated
phrase is saved after it's first evaluation. To list saved phrases
without translations function =MISSING-TRANSLATIONS= is
available. It returns a list of form ={((LANG (PHRASES*))*)}=.
without translations, the function =MISSING-TRANSLATIONS= is
available. It returns a list of the form ={((LANG (PHRASES*))*)}=.
#+BEGIN_SRC lisp
==> (missing-translations)
......@@ -159,24 +160,25 @@
Such output means, that language =PL= doesn't have translations for
"phrase-1", "phrase-2" and "phrase-3", while =BG= doesn't have
translations for "phrase-1" and "phrase-3". Languages, which have
translations for "phrase-1" and "phrase-3". Languages which have
all translations are filtered and they don't appear in the result.
** Different times of the resolution
Library may work in two different modes which dictate time, when
the actual translation is performed. Strings may be translated at
the load-time, or at the run-time.
The library may work in two different modes which dictate the time
when the actual translation is performed. Strings may be translated
at load-time, or at run-time.
First approach is faster, because it doesn't require any processing
at the run-time, while the second is much more flexible allowing
changing dictionaries and translations when the program is running
or per- lexical scope basis.
The first approach is faster, because it doesn't require any
processing at run-time, while the second is much more flexible
allowing the change of dictionaries and translations when the
program is running or depending on lexically scoped value of the
parameter =TRANSLATE:*LANGUAGE*=.
It is important to remember, that when translations are done at the
run-time, strings predated by =#t= are transformed to function calls
and they may work not as expected in the context, where enclosing
macro prevents their evaluation.
It is important to remember that, when translations are done at
run-time, strings preceded by =#t= are transformed to function
calls and they may work not as expected in the context where
enclosing macro prevents their evaluation.
#+BEGIN_SRC common-lisp
==> (setf translate:*mode* :run-time)
......@@ -197,11 +199,11 @@
(TRANSLATE:TRANSLATE "hello")
#+END_SRC
When translation is performed at the load-time it has to be present
before actual phrase is used (i.e. in lambda expression), because
phrases are resolved to their translations immediately. That also
means, that changing =*LANGUAGE*= in the future won't affect
translations resolved earlier.
When translation is performed at load-time, the translation has to
be present before the actual phrase is used (e.g. in a lambda
expression), because phrases are resolved to their translations
immediately. That also means that changing =TRANSLATE:*LANGUAGE*=
in the future won't affect translations resolved earlier.
#+BEGIN_SRC common-lisp
==> (setf translate:*mode* :load-time)
......@@ -233,34 +235,34 @@
"Hello"
#+END_SRC
Translation at run-time is better when programmer wants to add
translations ad-hoc or wants to switch languages when application
is running. Load-time translation is more suitable for static
translations for deployed applications or where macros prevent
necessary evaluation of the expressions. Also when programmer wants
to add translations in the future (if language is bound to nil and
resolution is performed at load-time the expression =#t="hello
world" means the same as the "hello world".
Translation at run-time is better when the programmer wants to add
translations ad-hoc or wants to switch languages when the
application is running. Load-time translation is more suitable for
static translations for deployed applications or where macros
prevent necessary evaluation of the expressions. Also when the
programmer wants to add translations in the future (if language is
bound to nil and resolution is performed at load-time the
expression =#t="hello world" means the same as the "hello world").
* Reference
** Parameters
*** =*LANGUAGE*=
#+BEGIN_SRC text
This variable holds the current language designator (predicate
used for comparison is =EQL=). If bound to =NIL=, translation
works the same way as =IDENTITY= function.
This variable holds the current language designator (the predicate
used for comparison is =EQL=). If bound to =NIL=, translation works
the same way as the =IDENTITY= function.
#+END_SRC
*** =*RESOLUTION-TIME*=
#+BEGIN_SRC text
Applicable values are =:LOAD-TIME= and =:RUN-TIME= (the latter is
Applicable values are =:LOAD-TIME= and =:RUN-TIME= (the latter is the
default). The variable controls time of actual resolution.
If it's the =:LOAD-TIME=, then resolution is performed when the
reader encounters =#t= dispatch macro character, while setting the
variable to =:RUN-TIME= translates =#t="string" to form
=(TRANSLATE "string")= and resolution takes place at the time of
the form evaluation.
If it's the =:LOAD-TIME=, then resolution is performed when the reader
encounters the =#t= dispatch macro character, while setting the
variable to =:RUN-TIME= translates =#t="string" to the form
=(TRANSLATE "string")= and resolution takes place at the time of the
form evaluation.
#+END_SRC
** Functions
......@@ -271,9 +273,9 @@
DEFINE-LANGUAGE (NAME &REST TRANSLATIONS) [Function]
Define language NAME with provided TRANSLATIONS
If LANGUAGE exists continuable error is signalled, which allows either
dropping the operation or superseeding already defined language.
TRANSLATIONS are alternatery phrases and their corresponding objects.
If LANGUAGE exists, a continuable error is signalled, which allows either
dropping the operation or superseding the language which is already defined.
TRANSLATIONS are alternating phrases and their corresponding objects.
-----------------------------------------------------------------------------
#+END_SRC
......@@ -284,8 +286,8 @@
ADD-SINGLE-TRANSLATION (LANGUAGE PHRASE TRANSLATION) [Function]
Add TRANSLATION of PHRASE for given LANGUAGE
If LANGUAGE doesn't exist it is implicitly created and the warning is
emited.
If LANGUAGE doesn't exist, it is implicitly created and a warning is
emmited.
-----------------------------------------------------------------------------
#+END_SRC
......@@ -294,7 +296,7 @@
ADD-TRANSLATIONS - external symbol in TRANSLATE package
-----------------------------------------------------------------------------
ADD-TRANSLATIONS (LANGUAGE &REST TRANSLATIONS) [Function]
Add any number of TRANSLATIONS for given LANGUAGE
Add any number of TRANSLATIONS for the given LANGUAGE
-----------------------------------------------------------------------------
#+END_SRC
......@@ -303,12 +305,13 @@
TRANSLATE - external symbol in TRANSLATE package
-----------------------------------------------------------------------------
TRANSLATE (PHRASE &OPTIONAL (LANGUAGE *LANGUAGE*)) [Function]
Find translation of PHRASE in the store associated with LANGUAGE
Find the translation of PHRASE in the store associated with LANGUAGE
If LANGUAGE is NIL, then this is the same as the IDENTITY function. If
provided LANGUAGE isn't defined the store is explicitly created. If no
PHRASE is defined for a given language, it is stored for later
translation and replaced by PHRASE surrunded by curly brackets.
the provided LANGUAGE isn't defined, the store is explicitly
created. If no PHRASE is defined for a given language, it is stored
for later translation and replaced by PHRASE surrunded by curly
brackets.
-----------------------------------------------------------------------------
#+END_SRC
......@@ -317,7 +320,7 @@
MISSING-TRANSLATIONS - external symbol in TRANSLATE package
-----------------------------------------------------------------------------
MISSING-TRANSLATIONS [Function]
Creates list of phrases which aren't translated for defined
languages. Retruns list of form: ({(LANG ({PHRASE}*))}*)
Creates a list of phrases which aren't translated for the defined
languages. Returns a list of form: ({(LANG ({PHRASE}*))}*)
-----------------------------------------------------------------------------
#+END_SRC
......@@ -15,9 +15,10 @@ or :load-time")
(defun define-language (name &rest translations)
"Define language NAME with provided TRANSLATIONS
If LANGUAGE exists continuable error is signalled, which allows either
dropping the operation or superseeding already defined language.
TRANSLATIONS are alternatery phrases and their corresponding objects."
If LANGUAGE exists, a continuable error is signalled, which allows
either dropping the operation or superseding the language which is
already defined. TRANSLATIONS are alternating phrases and their
corresponding objects."
(when (getf *translations* name)
(cerror "Supersede language."
"Language ~A is already defined." name))
......@@ -32,8 +33,8 @@ TRANSLATIONS are alternatery phrases and their corresponding objects."
(defun add-single-translation (language phrase translation)
"Add TRANSLATION of PHRASE for given LANGUAGE
If LANGUAGE doesn't exist it is implicitly created and the warning is
emited."
If LANGUAGE doesn't exist, it is implicitly created and a warning is
emmited."
(check-type phrase string)
(let ((dict (car (or (getf *translations* language)
(progn
......@@ -44,7 +45,7 @@ emited."
(setf (gethash phrase dict) translation)))
(defun add-translations (language &rest translations)
"Add any number of TRANSLATIONS for given LANGUAGE"
"Add any number of TRANSLATIONS for the given LANGUAGE"
(do* ((tr translations (cddr tr)))
((endp tr) T)
(destructuring-bind (phrase trans &rest ign) tr
......@@ -53,12 +54,13 @@ emited."
;; resolution
(defun translate (phrase &optional (language *language*))
"Find translation of PHRASE in the store associated with LANGUAGE
"Find the translation of PHRASE in the store associated with LANGUAGE
If LANGUAGE is NIL, then this is the same as the IDENTITY function. If
provided LANGUAGE isn't defined the store is explicitly created. If no
PHRASE is defined for a given language, it is stored for later
translation and replaced by PHRASE surrunded by curly brackets."
If LANGUAGE is NIL, then this is the same as the the IDENTITY
function. If the provided LANGUAGE isn't defined, the store is
explicitly created. If no PHRASE is defined for a given language, it
is stored for later translation and replaced by PHRASE surrunded by
curly brackets."
(check-type phrase string)
(if language
(let ((lang
......@@ -91,8 +93,8 @@ translation and replaced by PHRASE surrunded by curly brackets."
;; missing translations
(defun missing-translations ()
"Creates list of phrases which aren't translated for defined
languages. Retruns list of form: ({(LANG ({PHRASE}*))}*)"
"Creates a list of phrases which aren't translated for the defined
languages. Returns a list of form: ({(LANG ({PHRASE}*))}*)"
(do* (acc
(reminder *translations* (cddr reminder))
(elt (second (cadr reminder))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment