• Publicity: Public Only All

lang-util-procs.tcl

Utility routines for translating pages. Many of these procs deal with message keys embedded in strings with the #key# or the <#key text#> syntax.

This is free software distributed under the terms of the GNU Public License. Full text of the license is available from the GNU Project: http://www.fsf.org/copyleft/gpl.html

Location:
packages/acs-lang/tcl/lang-util-procs.tcl
Created:
10 September 2000
Authors:
Jeff Davis <davis@xarg.net>
Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>
Peter Marklund <peter@collaboraid.biz>
Lars Pind <lars@collaboraid.biz>
Christian Hvid
CVS Identification:
$Id: lang-util-procs.tcl,v 1.56 2024/09/11 06:15:48 gustafn Exp $

Procedures in this file

Detailed information

lang::util::charset_for_locale (public)

 lang::util::charset_for_locale locale

Returns the MIME charset name corresponding to a locale.

Parameters:
locale (required)
Name of a locale, as language_COUNTRY using ISO 639 and ISO 3166
Returns:
IANA MIME character set name
Author:
Henry Minsky <hqm@mit.edu>

Testcases:
test_get_locales

lang::util::convert_adp_variables_to_percentage_signs (private)

 lang::util::convert_adp_variables_to_percentage_signs text

Convert ADP variables to percentage_signs - the notation used to interpolate variable values into acs-lang messages.

Parameters:
text (required)
Author:
Peter Marklund

Testcases:
util__convert_adp_variables_to_percentage_signs

lang::util::convert_percentage_signs_to_adp_variables (private)

 lang::util::convert_percentage_signs_to_adp_variables text

Convert percentage_signs message vars to adp var syntax.

Parameters:
text (required)
Author:
Peter Marklund
See Also:

Testcases:
util__convert_adp_variables_to_percentage_signs

lang::util::convert_to_i18n (public)

 lang::util::convert_to_i18n [ -locale locale ] \
    [ -package_key package_key ] [ -message_key message_key ] \
    [ -prefix prefix ] -text text [ -object_id object_id ]

Internationalising of Attributes. This is done by storing the attribute with its acs-lang key

Switches:
-locale (optional, defaults to "en_US")
-package_key (optional, defaults to "acs-translations")
-message_key (optional)
-prefix (optional)
-text (required)
-object_id (optional)
bind the newly created message key to this acs_object id. Upon object's deletion, the message key will be deleted as well.

Testcases:
lang_test__convert_to_i18n, group_localization

lang::util::default_locale_from_lang (public)

 lang::util::default_locale_from_lang language

Returns an enabled default locale for a language. If a language only has one locale then that locale is returned. If no locale could be found the empty string is returned.

Parameters:
language (required)
Name of a country, using ISO-3166 two letter code
Returns:
Default locale
Author:
Henry Minsky <hqm@mit.edu>

Testcases:
default_locale_from_lang

lang::util::default_locale_from_lang_not_cached (private)

 lang::util::default_locale_from_lang_not_cached language

Returns the default locale for a language. Not cached.

Parameters:
language (required)
Name of a language, using a two or three letter ISO code
Returns:
Default locale
Author:
Henry Minsky <hqm@mit.edu>
See Also:

Testcases:
No testcase defined.

lang::util::edit_lang_key_url (public)

 lang::util::edit_lang_key_url -message message \
    [ -package_key package_key ]

Generates the URL to edit a message key.

Switches:
-message (required)
key with or without hashes, such as \#acs-admin.Actions\# or acs-admin.Actions.
-package_key (optional, defaults to "acs-translations")
must correspond to that in the message key.
Returns:
a local URL or the empty string when no URL can be generated.

Testcases:
test_edit_lang_key_url

lang::util::escape_vars_if_not_null (private)

 lang::util::escape_vars_if_not_null list

Processes a list of variables before they are passed into a regexp command.

Parameters:
list (required)
List of variable names

Testcases:
No testcase defined.

lang::util::get_hash_indices (public)

 lang::util::get_hash_indices multilingual_string

Returns a list of two element lists containing the start and end indices of a #message_key# match in the multilingual string. This proc is used by the localize proc.

Parameters:
multilingual_string (required)
Author:
Peter marklund <peter@collaboraid.biz>

Testcases:
util__get_hash_indices

lang::util::get_label (public)

 lang::util::get_label locale

Returns the label (name) of locale

Parameters:
locale (required)
Code for the locale, eg "en_US"
Returns:
String containing the label for the locale
Author:
Bruno Mattarollo <bruno.mattarollo@ams.greenpeace.org>

Testcases:
test_get_locales

lang::util::get_locale_options (public)

 lang::util::get_locale_options

Return a list of locales know to the system

Testcases:
test_get_locales

lang::util::get_locale_options_not_cached (private)

 lang::util::get_locale_options_not_cached

Return all enabled locales in the system in a format suitable for the options argument of a form.

Author:
Lars Pind

Testcases:
No testcase defined.

lang::util::get_message_lookups (private)

 lang::util::get_message_lookups

Get the list of all message keys looked up so far during the current request.

Author:
Peter Marklund

Testcases:
No testcase defined.

lang::util::get_regexp_indices (private)

 lang::util::get_regexp_indices multilingual_string regexp_pattern

Returns a list of two element lists containing the start and end indices of what is captured by the first parenthesis in the given regexp pattern in the multilingual string. The regexp pattern must follow the syntax of the expression argument to the Tcl regexp command. It must also contain exactly one capturing parenthesis for the pieces of text that indices are to be returned for.

Parameters:
multilingual_string (required)
regexp_pattern (required)
Author:
Peter marklund <peter@collaboraid.biz>
See Also:
  • get_hash_indices

Testcases:
No testcase defined.

lang::util::get_temporary_tags_indices (public)

 lang::util::get_temporary_tags_indices adp_file_string

Given the contents of an adp file return the indices of the start and end chars of embedded message keys on the syntax: <#package_key.message_key Some en_US text#>

Parameters:
adp_file_string (required)
Author:
Peter marklund <peter@collaboraid.biz>

Testcases:
util__replace_temporary_tags_with_lookups

lang::util::iso6392_from_language (public)

 lang::util::iso6392_from_language -language language

Returns the ISO-639-2 code for a language.

Switches:
-language (required)
Language, using ISO-639 code (2 or 3 chars)
Returns:
The ISO-639-2 terminology code for the language

Testcases:
test_get_locales

lang::util::iso6392_from_locale (public)

 lang::util::iso6392_from_locale -locale locale

Returns the ISO-639-2 code for a locale.

Switches:
-locale (required)
Locale to get the language ISO-639-2 code for
Returns:
The ISO-639-2 language code for the locale

Testcases:
test_get_locales

lang::util::lang_sort (public, deprecated)

 lang::util::lang_sort field [ locale ]
Deprecated. Invoking this procedure generates a warning.

Each locale can have a different alphabetical sort order. You can test this proc with the following data:

    insert into lang_testsort values ('lama');
    insert into lang_testsort values ('lhasa');
    insert into lang_testsort values ('llama');
    insert into lang_testsort values ('lzim');
    
DEPRECATED: this api only supports Oracle. It also uses hardcoded mapping between language and collation. It is unclear if an api is needed for this, or if one can just have database-specific SQL in xql files in order to achieve cross-db collation behavior.

Parameters:
field (required)
Name of Oracle column
locale (optional)
Locale for sorting. If locale is unspecified just return the column name
Returns:
Language aware version of field for Oracle ORDER BY clause.
Author:
Jeff Davis <davis@xarg.net>
See Also:

Testcases:
No testcase defined.

lang::util::language_label (public)

 lang::util::language_label -language language

Returns the ISO-639 label for a language code.

Switches:
-language (required)
Language, using ISO-639 code (2 or 3 chars)
Returns:
The ISO-639 label for the language

Testcases:
test_get_locales

lang::util::localize (public)

 lang::util::localize string_with_hashes [ locale ]

Takes a string with embedded message keys on the format #message_key_name# and returns the same string but with the message keys (and their surrounding hash marks) replaced with the corresponding value in the message catalog. Message lookup is done with the locale of the request. If message lookup fails for a certain key then a translation missing message will be used instead.

Parameters:
string_with_hashes (required)
locale (optional)
Author:
Peter marklund <peter@collaboraid.biz>

Testcases:
lang_test__lang_user_site_wide_locale, localize, test_localize_list_of_lists, ad_context_bar_multirow, object_type_hierarchy

lang::util::localize_list_of_lists (public)

 lang::util::localize_list_of_lists [ -list list ]

localize the elements of a list_of_lists

Switches:
-list (optional)

Testcases:
test_localize_list_of_lists

lang::util::message_key_regexp (public)

 lang::util::message_key_regexp

Regular expression for recognizing message keys in the form #package_name.key#.

See Also:

Testcases:
test_message_regexp

lang::util::message_tag_regexp (public)

 lang::util::message_tag_regexp

The regexp expression used by proc get_temporary_tags_indices and elsewhere to extract temporary message catalog tags (<#...#>) from ADP and Tcl files. The first sub match of the expression is the whole tag, the second sub match is the message key, and the third sub match is the message text in en_US locale.

Author:
Peter marklund <peter@collaboraid.biz>
See Also:

Testcases:
test_message_regexp

lang::util::nls_language_from_language (public)

 lang::util::nls_language_from_language language

Returns the nls_language name for a language

Parameters:
language (required)
Name of a country, using ISO-3166 two letter code
Returns:
The nls_language name of the language.
Author:
Henry Minsky <hqm@mit.edu>

Testcases:
test_get_locales

lang::util::record_message_lookup (private)

 lang::util::record_message_lookup message_key

Record a message lookup in translator mode. In translator mode we collect all message lookups at the bottom of the page for translation.

Parameters:
message_key (required)
Author:
Peter Marklund

Testcases:
No testcase defined.

lang::util::remove_gt_lt (private)

 lang::util::remove_gt_lt s

Removes < > and replaces them with &lt &gt;

Parameters:
s (required)

Testcases:
No testcase defined.

lang::util::replace_adp_text_with_message_tags (public)

 lang::util::replace_adp_text_with_message_tags file_name mode [ keys ]

Prepares an .adp-file for localization by inserting temporary hash-tags around text strings that looks like unlocalized plain text. Needless to say this is a little shaky so not all plain text is caught and the script may insert hash-tags around stuff that should not be localized. It is conservative though. There are two modes the script can be run in: - report : do *not* write changes to the file but return a report with suggested changes. - write : write changes in the file - it expects a list of keys and will insert them in the order implied by the report - a report is also returned.

Parameters:
file_name (required)
The name of the adp file to do replacements in.
mode (required)
Either report or write.
keys (optional)
A list of keys to use for the texts that may be provided in write mode. If the keys are not provided then autogenerated keys will be used. If a supplied key is the empty string this indicates that the corresponding text should be left untouched.
Returns:
The report is list of two lists: The first being a list of pairs (key, text with context) and the second is a list of suspious looking garbage. In report mode the keys are suggested keys and in write mode the keys are the keys supplied in the keys parameter.
Authors:
Christian Hvid
Peter Marklund
Jeff Davis

Testcases:
util__replace_adp_text_with_message_tags

lang::util::replace_temporary_tags_with_lookups (public)

 lang::util::replace_temporary_tags_with_lookups file_list

Modify the given ADP or Tcl files by replacing occurencies of message keys with message lookups (i.e. #package_key.message_key# for ADP files and [_ "package_key.message_key"] for Tcl files) and create entries in the catalog file for each of these keys. If the short hand form <#_ Some en_US text#> is used then the key will be auto-generated based on the text. Returns the number of replacements done. This procedure only reads from and writes to the catalog file specified (the en_US catalog file per default) of the package that the files belong to, the database is not accessed in any way.

Parameters:
file_list (required)
A list of paths to .adp or .tcl files to do replacements in. The paths should be relative to $::acs::rootdir. All files must belong to the same package.
Author:
Peter marklund <peter@collaboraid.biz>

Testcases:
util__replace_temporary_tags_with_lookups

lang::util::suggest_key (private)

 lang::util::suggest_key text

Suggest a key for given text.

Parameters:
text (required)

Testcases:
No testcase defined.

lang::util::translator_mode_p (public)

 lang::util::translator_mode_p

Whether translator mode is enabled for this session or not. Translator mode will cause all non-translated messages to appear as a link to a page where the message can be translated, instead of the default "not translated" message.

Returns:
1 if translator mode is enabled, 0 otherwise. Returns 0 if there is no HTTP connection.
Author:
Lars Pind <lars@collaboraid.biz>
Created:
October 24, 2002
See Also:

Testcases:
test_translator_mode

lang::util::translator_mode_set (public)

 lang::util::translator_mode_set translator_mode_p

Sets whether translator mode is enabled for this session or not.

Parameters:
translator_mode_p (required)
1 if you want translator mode to be enabled, 0 otherwise.
Author:
Lars Pind <lars@collaboraid.biz>
Created:
October 24, 2002
See Also:

Testcases:
test_translator_mode
[ show source ]