• 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.54.2.13 2021/10/04 10:15:42 antoniop 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 - 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>

Partial Call Graph (max 5 caller/called nodes):
%3 lang::catalog::get_catalog_file_path lang::catalog::get_catalog_file_path (private) lang::util::charset_for_locale lang::util::charset_for_locale lang::catalog::get_catalog_file_path->lang::util::charset_for_locale lang::conn::charset lang::conn::charset (public) lang::conn::charset->lang::util::charset_for_locale

Testcases:
No testcase defined.

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 (defaults to "en_US") (optional)
-package_key (defaults to "acs-translations") (optional)
-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.

Partial Call Graph (max 5 caller/called nodes):
%3 test_group_localization group_localization (test acs-subsite) lang::util::convert_to_i18n lang::util::convert_to_i18n test_group_localization->lang::util::convert_to_i18n test_lang_test__convert_to_i18n lang_test__convert_to_i18n (test acs-lang) test_lang_test__convert_to_i18n->lang::util::convert_to_i18n Class ::xowiki::formfield::localized_text Class ::xowiki::formfield::localized_text (public) Class ::xowiki::formfield::localized_text->lang::util::convert_to_i18n group::new group::new (public) group::new->lang::util::convert_to_i18n group::update group::update (public) group::update->lang::util::convert_to_i18n subsite::after_upgrade subsite::after_upgrade (private) subsite::after_upgrade->lang::util::convert_to_i18n

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 - Name of a country, using ISO-3166 two letter code
Returns:
Default locale
Author:
Henry Minsky <hqm@mit.edu>

Partial Call Graph (max 5 caller/called nodes):
%3 test_default_locale_from_lang default_locale_from_lang (test acs-lang) lang::util::default_locale_from_lang lang::util::default_locale_from_lang test_default_locale_from_lang->lang::util::default_locale_from_lang category::get_name category::get_name (public) category::get_name->lang::util::default_locale_from_lang lang::conn::browser_locale lang::conn::browser_locale (private) lang::conn::browser_locale->lang::util::default_locale_from_lang lang::message::check lang::message::check (public) lang::message::check->lang::util::default_locale_from_lang lang::message::lookup lang::message::lookup (public) lang::message::lookup->lang::util::default_locale_from_lang lang::message::register lang::message::register (public) lang::message::register->lang::util::default_locale_from_lang

Testcases:
default_locale_from_lang

lang::util::edit_lang_key_url (public)

 lang::util::edit_lang_key_url -message message \
    [ -package_key package_key ]
Switches:
-message (required)
-package_key (defaults to "acs-translations") (optional)

Partial Call Graph (max 5 caller/called nodes):
%3

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
Author:
Peter marklund <peter@collaboraid.biz>

Partial Call Graph (max 5 caller/called nodes):
%3 test_util__get_hash_indices util__get_hash_indices (test acs-lang) lang::util::get_hash_indices lang::util::get_hash_indices test_util__get_hash_indices->lang::util::get_hash_indices lang::util::localize lang::util::localize (public) lang::util::localize->lang::util::get_hash_indices packages/acs-admin/www/apm/version-i18n.tcl packages/acs-admin/ www/apm/version-i18n.tcl packages/acs-admin/www/apm/version-i18n.tcl->lang::util::get_hash_indices

Testcases:
util__get_hash_indices

lang::util::get_label (public)

 lang::util::get_label locale

Returns the label (name) of locale

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

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-lang/www/admin/batch-editor.tcl packages/acs-lang/ www/admin/batch-editor.tcl lang::util::get_label lang::util::get_label packages/acs-lang/www/admin/batch-editor.tcl->lang::util::get_label packages/acs-lang/www/admin/edit-description.tcl packages/acs-lang/ www/admin/edit-description.tcl packages/acs-lang/www/admin/edit-description.tcl->lang::util::get_label packages/acs-lang/www/admin/edit-localized-message.tcl packages/acs-lang/ www/admin/edit-localized-message.tcl packages/acs-lang/www/admin/edit-localized-message.tcl->lang::util::get_label packages/acs-lang/www/admin/export-locale-to-files.tcl packages/acs-lang/ www/admin/export-locale-to-files.tcl packages/acs-lang/www/admin/export-locale-to-files.tcl->lang::util::get_label packages/acs-lang/www/admin/import-locale-from-files.tcl packages/acs-lang/ www/admin/import-locale-from-files.tcl packages/acs-lang/www/admin/import-locale-from-files.tcl->lang::util::get_label

Testcases:
No testcase defined.

lang::util::get_locale_options (public)

 lang::util::get_locale_options

Return a list of locales know to the system

Partial Call Graph (max 5 caller/called nodes):
%3

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
Author:
Peter marklund <peter@collaboraid.biz>

Partial Call Graph (max 5 caller/called nodes):
%3 test_util__replace_temporary_tags_with_lookups util__replace_temporary_tags_with_lookups (test acs-lang) lang::util::get_temporary_tags_indices lang::util::get_temporary_tags_indices test_util__replace_temporary_tags_with_lookups->lang::util::get_temporary_tags_indices lang::util::replace_temporary_tags_with_lookups lang::util::replace_temporary_tags_with_lookups (public) lang::util::replace_temporary_tags_with_lookups->lang::util::get_temporary_tags_indices packages/acs-admin/www/apm/version-i18n.tcl packages/acs-admin/ www/apm/version-i18n.tcl packages/acs-admin/www/apm/version-i18n.tcl->lang::util::get_temporary_tags_indices

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

Partial Call Graph (max 5 caller/called nodes):
%3 lang::conn::language lang::conn::language (public) lang::util::iso6392_from_language lang::util::iso6392_from_language lang::conn::language->lang::util::iso6392_from_language lang::system::language lang::system::language (public) lang::system::language->lang::util::iso6392_from_language lang::user::language lang::user::language (public) lang::user::language->lang::util::iso6392_from_language lang::util::iso6392_from_locale lang::util::iso6392_from_locale (public) lang::util::iso6392_from_locale->lang::util::iso6392_from_language

Testcases:
No testcase defined.

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

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.

lang::util::lang_sort (public)

 lang::util::lang_sort field [ locale ]

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');
    

Parameters:
field - 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>

Partial Call Graph (max 5 caller/called nodes):
%3

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

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-lang/www/admin/locale-new.tcl packages/acs-lang/ www/admin/locale-new.tcl lang::util::language_label lang::util::language_label packages/acs-lang/www/admin/locale-new.tcl->lang::util::language_label

Testcases:
No testcase defined.

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
locale (optional)
Author:
Peter marklund <peter@collaboraid.biz>

Partial Call Graph (max 5 caller/called nodes):
%3 test_ad_context_bar_multirow ad_context_bar_multirow (test acs-tcl) lang::util::localize lang::util::localize test_ad_context_bar_multirow->lang::util::localize test_localize localize (test acs-lang) test_localize->lang::util::localize Class ::cookieconsent::CookieConsent Class ::cookieconsent::CookieConsent (public) Class ::cookieconsent::CookieConsent->lang::util::localize Class ::xo::lti::LTI Class ::xo::lti::LTI (public) Class ::xo::lti::LTI->lang::util::localize Class ::xowf::test_item::Answer_manager Class ::xowf::test_item::Answer_manager (public) Class ::xowf::test_item::Answer_manager->lang::util::localize Class ::xowiki::formfield::localized_text Class ::xowiki::formfield::localized_text (public) Class ::xowiki::formfield::localized_text->lang::util::localize acs_object_type_hierarchy acs_object_type_hierarchy (public) acs_object_type_hierarchy->lang::util::localize

Testcases:
localize, ad_context_bar_multirow

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)

Partial Call Graph (max 5 caller/called nodes):
%3 template::data::transform::party_search template::data::transform::party_search (private) lang::util::localize_list_of_lists lang::util::localize_list_of_lists template::data::transform::party_search->lang::util::localize_list_of_lists

Testcases:
No testcase defined.

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:

Partial Call Graph (max 5 caller/called nodes):
%3 Class ::xowiki::formfield::localized_text Class ::xowiki::formfield::localized_text (public) lang::util::message_key_regexp lang::util::message_key_regexp Class ::xowiki::formfield::localized_text->lang::util::message_key_regexp Class ::xowiki::includelet::folders Class ::xowiki::includelet::folders (public) Class ::xowiki::includelet::folders->lang::util::message_key_regexp group::new group::new (public) group::new->lang::util::message_key_regexp

Testcases:
No testcase defined.

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:

Partial Call Graph (max 5 caller/called nodes):
%3 lang::util::get_temporary_tags_indices lang::util::get_temporary_tags_indices (public) lang::util::message_tag_regexp lang::util::message_tag_regexp lang::util::get_temporary_tags_indices->lang::util::message_tag_regexp lang::util::replace_temporary_tags_with_lookups lang::util::replace_temporary_tags_with_lookups (public) lang::util::replace_temporary_tags_with_lookups->lang::util::message_tag_regexp

Testcases:
No testcase defined.

lang::util::nls_language_from_language (public)

 lang::util::nls_language_from_language language

Returns the nls_language name for a language

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

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-templating/tcl/spellcheck-init.tcl packages/acs-templating/ tcl/spellcheck-init.tcl lang::util::nls_language_from_language lang::util::nls_language_from_language packages/acs-templating/tcl/spellcheck-init.tcl->lang::util::nls_language_from_language

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 - The name of the adp file to do replacements in.
mode - 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

Partial Call Graph (max 5 caller/called nodes):
%3 test_util__replace_adp_text_with_message_tags util__replace_adp_text_with_message_tags (test acs-lang) lang::util::replace_adp_text_with_message_tags lang::util::replace_adp_text_with_message_tags test_util__replace_adp_text_with_message_tags->lang::util::replace_adp_text_with_message_tags packages/acs-admin/www/apm/version-i18n-process-2.tcl packages/acs-admin/ www/apm/version-i18n-process-2.tcl packages/acs-admin/www/apm/version-i18n-process-2.tcl->lang::util::replace_adp_text_with_message_tags packages/acs-admin/www/apm/version-i18n-process.tcl packages/acs-admin/ www/apm/version-i18n-process.tcl packages/acs-admin/www/apm/version-i18n-process.tcl->lang::util::replace_adp_text_with_message_tags packages/acs-admin/www/apm/version-i18n.tcl packages/acs-admin/ www/apm/version-i18n.tcl packages/acs-admin/www/apm/version-i18n.tcl->lang::util::replace_adp_text_with_message_tags

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 autogenerated 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 - 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>

Partial Call Graph (max 5 caller/called nodes):
%3 test_util__replace_temporary_tags_with_lookups util__replace_temporary_tags_with_lookups (test acs-lang) lang::util::replace_temporary_tags_with_lookups lang::util::replace_temporary_tags_with_lookups test_util__replace_temporary_tags_with_lookups->lang::util::replace_temporary_tags_with_lookups packages/acs-admin/www/apm/version-i18n-process-2.tcl packages/acs-admin/ www/apm/version-i18n-process-2.tcl packages/acs-admin/www/apm/version-i18n-process-2.tcl->lang::util::replace_temporary_tags_with_lookups

Testcases:
util__replace_temporary_tags_with_lookups

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:

Partial Call Graph (max 5 caller/called nodes):
%3 Class ::xowiki::formfield::FormField Class ::xowiki::formfield::FormField (public) lang::util::translator_mode_p lang::util::translator_mode_p Class ::xowiki::formfield::FormField->lang::util::translator_mode_p adp_parse_ad_conn_file adp_parse_ad_conn_file (public) adp_parse_ad_conn_file->lang::util::translator_mode_p lang::message::lookup lang::message::lookup (public) lang::message::lookup->lang::util::translator_mode_p packages/acs-bootstrap-installer/installer/www/blank-master.tcl packages/acs-bootstrap-installer/ installer/www/blank-master.tcl packages/acs-bootstrap-installer/installer/www/blank-master.tcl->lang::util::translator_mode_p packages/acs-developer-support/lib/toolbar.tcl packages/acs-developer-support/ lib/toolbar.tcl packages/acs-developer-support/lib/toolbar.tcl->lang::util::translator_mode_p

Testcases:
No testcase defined.

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 - 1 if you want translator mode to be enabled, 0 otherwise.
Author:
Lars Pind <lars@collaboraid.biz>
Created:
October 24, 2002

See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-lang/www/admin/translator-mode-toggle.tcl packages/acs-lang/ www/admin/translator-mode-toggle.tcl lang::util::translator_mode_set lang::util::translator_mode_set packages/acs-lang/www/admin/translator-mode-toggle.tcl->lang::util::translator_mode_set

Testcases:
No testcase defined.
[ show source ]