- Publicity: Public Only All
lang-catalog-procs.tcl
Routines for importing/exporting messages from/to XML message catalog files. Every OpenACS package has one message catalog file for each locale (language and region) that its UI supports. Importing of messages means reading the messages from XML catalog files and storing them in the database. Exporting of messages refers to the opposite process. The key procedures in this library are:
- lang::catalog::import - Import all catalog files on the system into the database. Can be restricted to only import from one package and only certain locales.
- lang::catalog::import_from_file - Import from a single catalog file
- lang::catalog::export - Export all messages in the database to catalog files. Can be restricted to only export from one package and only certain locales.
- lang::catalog::export_to_file - Export messages to a single file
- Location:
- packages/acs-lang/tcl/lang-catalog-procs.tcl
- Created:
- 10 September 2000
- Authors:
- Jeff Davis
- Peter Marklund <peter@collaboraid.biz>
- Lars Pind <lars@collaboraid.biz>
- CVS Identification:
$Id: lang-catalog-procs.tcl,v 1.63 2024/10/08 13:35:13 antoniop Exp $
Procedures in this file
- lang::catalog::all_messages_for_package_and_locale (private)
- lang::catalog::assert_catalog_file (private)
- lang::catalog::default_charset_if_unsupported (private)
- lang::catalog::export (public)
- lang::catalog::export_to_file (private)
- lang::catalog::get_catalog_file_path (private)
- lang::catalog::get_catalog_files (private)
- lang::catalog::get_catalog_paths_for_import (private)
- lang::catalog::get_required_xml_attribute (private)
- lang::catalog::import (public)
- lang::catalog::import_from_file (private)
- lang::catalog::import_messages (private)
- lang::catalog::is_upgrade_backup_file (private)
- lang::catalog::last_sync_messages (private)
- lang::catalog::message_backup_file_prefix (private)
- lang::catalog::messages_in_db (private)
- lang::catalog::package_catalog_dir (public)
- lang::catalog::package_delete (public)
- lang::catalog::package_has_files_in_locale_p (private)
- lang::catalog::parse (private)
- lang::catalog::read_file (private)
- lang::catalog::translate (private)
- lang::catalog::uninitialized_packages (private)
Detailed information
lang::catalog::all_messages_for_package_and_locale (private)
lang::catalog::all_messages_for_package_and_locale package_key locale
Set a multirow with name all_messages locally in the callers scope with the columns message_key and message for all message keys that do not have an upgrade status of deleted.
- Parameters:
- package_key (required)
- locale (required)
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::assert_catalog_file (private)
lang::catalog::assert_catalog_file catalog_file_path
Throws an error if the given path is not valid for a catalog file.
- Parameters:
- catalog_file_path (required)
- Author:
- Peter Marklund
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::default_charset_if_unsupported (private)
lang::catalog::default_charset_if_unsupported charset
Will return the system default charset and issue a warning in the log file if the given charset is not supported by tcl. Otherwise the given charset is simply returned.
- Parameters:
- charset (required)
- Authors:
- Jeff Davis
- Peter Marklund <peter@collaboraid.biz>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::export (public)
lang::catalog::export [ -package_key package_key ] \ [ -locales locales ]
Exports I18N messages from the database to XML catalog files. By default exports messages for all enabled packages and all enabled locales on the system. Can be restricted to export only for a certain package and/or a list of locales.
- Switches:
- -package_key (optional)
- A key of a package to restrict the export to
- -locales (optional)
- A list of locales to restrict the export to
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- test_catalog_import_export
lang::catalog::export_to_file (private)
lang::catalog::export_to_file [ -descriptions_list descriptions_list ] \ file_path messages_list
Export messages for a certain locale and package from the database to a given XML catalog file. If the catalog file already exists it will be backed up to a file with the same name but the extension .orig added to it. If there is an old backup file no new backup is done.
- Switches:
- -descriptions_list (optional)
- Parameters:
- file_path (required)
- The path of the catalog file to write messages to. The filename needs to be parseable by apm_parse_catalog_path. The file and the catalog directory will be created if they don't exist.
- messages_list (required)
- A list with message keys on even indices followed by corresponding messages on odd indices.
- Author:
- Peter Marklund <peter@collaboraid.biz>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- util__replace_temporary_tags_with_lookups
lang::catalog::get_catalog_file_path (private)
lang::catalog::get_catalog_file_path \ [ -backup_from_version backup_from_version ] \ [ -backup_to_version backup_to_version ] -package_key package_key \ -locale locale [ -charset charset ]
Get the full path of the catalog file for a given package, and locale.
- Switches:
- -backup_from_version (optional)
- -backup_to_version (optional)
- -package_key (required)
- -locale (required)
- -charset (optional)
- Should normally not be provided. Will force the charset to a certain value. If not provided an appropriate charset to write the locale in will be used.
- Author:
- Peter Marklund
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::get_catalog_files (private)
lang::catalog::get_catalog_files package_key
Return the full paths of all message catalog files of the given package.
- Parameters:
- package_key (required)
- The key of the package to return catalog file paths for
- Returns:
- A list of catalog file paths
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::get_catalog_paths_for_import (private)
lang::catalog::get_catalog_paths_for_import -package_key package_key \ [ -locales locales ]
Return a list of file paths for the catalog files of the given package. Can be restricted to only return files for certain locales. The list will be sorted in an order appropriate for import to the database.
- Switches:
- -package_key (required)
- The key of the package to get catalog file paths for
- -locales (optional)
- A list of locales to restrict the catalog files to
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- catalog_files_are_tdom_parsable_xml
lang::catalog::get_required_xml_attribute (private)
lang::catalog::get_required_xml_attribute element attribute
Return the value of the given attribute and raise an error if the value is missing or empty.
- Parameters:
- element (required)
- attribute (required)
- Author:
- Peter Marklund <peter@collaboraid.biz>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::import (public)
lang::catalog::import [ -package_key package_key ] \ [ -locales locales ] [ -initialize ] [ -cache ]
Import messages from catalog files to the database. By default all messages for enabled packages and enabled locales will be imported. Optionally, the import can be restricted to a certain package and/or a list of locales. Invokes the proc lang::catalog::import_messages that deals with multiple imports (upgrades).
- Switches:
- -package_key (optional)
- Restrict the import to the package with this key
- -locales (optional)
- A list of locales to restrict the import to
- -initialize (optional, boolean)
- Only load messages from packages that have never before had any message imported
- -cache (optional, boolean)
- Provide this switch if you want the proc to cache all the imported messages
- Returns:
- An array list containing the number of messages processed, number of messages added, number of messages updated, number of messages deleted by the import, and a list of errors produced. The keys of the array list are processed, added, updated, and deleted, and errors.
- Author:
- Peter Marklund
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- lang_test__lc_procs, locale_language_fallback, upgrade, test_catalog_import_export
lang::catalog::import_from_file (private)
lang::catalog::import_from_file file_path
Import messages for a certain locale and package from a given XML catalog file to the database. This procedure invokes lang::catalog::parse to read the catalog file and lang::message::register to register the messages with the system (updates database and cache).
The import should be considered an upgrade if the package has had messages imported before. In this case the proc lang::catalog::import_messages will be used to register the new messages with the system and handle the upgrade logic (a merge with what's in the database).
- Parameters:
- file_path (required)
- The absolute path of the XML file to import messages from. The path must be on valid format, see apm_is_catalog_file
- Returns:
- An array list containing the number of messages processed, number of messages added, number of messages updated, and the number of messages deleted by the import. The keys of the array list are processed, added, updated, and deleted.
- Author:
- Peter Marklund
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::import_messages (private)
lang::catalog::import_messages -file_messages_list file_messages_list \ -package_key package_key -locale locale
Import a given set of messages from a catalog file to the database for a certain package and locale. If we already have messages in the db for the given package and locale then a merge between the database messages and the file messages will be performed.
Foreach message to import, the base messages for the merge is the messages in the db from the last time db and catalog file were in sync for the corresponding message key. The first such sync point is the initial import of a message. After that, any export of messages to the filesystem will be a sync point. Also, after an upgrade, a large number of the resulting messages in the db will be identical to those in the file (the file messages take precedence on conflict) and those messages will also be sync points. A message being in sync between db and file is indicated by the lang_message.sync_time column being set to a not null value.
This proc is idempotent which means that it can be executed multiple times and after the first time it's been executed it won't have any effect on the db. See the corresponding acs-automated-testing test case called upgrade.
What follows below is a description of the logic of the proc in terms of its input, the cases considered, and the logical actions taken for each case.
There are three sets of keys, file, db, and base keys. For each key in the union of these keys there are three messages that can exist: the file message, the db message, and the base message. The base message serves as the base for the merge. We will distinguish all the different permutations of each of the three messages existing or not, and all permutations of the messages being different from each other. We don't distinguish how two messages are different, only whether they are different or not. In total that gives us 14 cases (permutations) to consider.
*** Exactly one of messages exists (3 cases): 1. base message (deleted in file and db). upgrade_action=none, conflict_p=f 2. db message (added in db). upgrade_action=none, conflict_p=f 3. file message (added in file). upgrade_action=add, conflict_p=f *** Exactly two of the messages exist (6 cases): - Base and file message (db message deleted): 4. Differ (conflicting change). upgrade_action=resurrect, conflict_p=t 5. No difference (no conflicting change). upgrade_action=none, conflict_p=f - Base and db message (file message deleted): 6. Differ (conflicting change): upgrade_action=delete, conflict_p=t 7. No difference (no conflicting change): upgrade_action=delete, conflict_p=f - File and db message (message added in both db and file): 8. Differ (conflicting change). upgrade_action=update, conflict_p=t 9. No difference (identical changes). upgrade_action=none, conflict_p=f *** All three messages exist (5 cases): 10. All the same. upgrade_action=none, conflict_p=f 11. File and base the same. upgrade_action=none, conflict_p=f 12. DB and base the same. upgrade_action=update, conflict_p=f 13. File and DB the same. upgrade_action=none, conflict_p=f 14. All different. upgrade_action=update, conflict_p=t
- Switches:
- -file_messages_list (required)
- An array list with message keys as keys and the message of those keys as values, i.e. (key, value, key, value, ...)
- -package_key (required)
- The package_key for the messages.
- -locale (required)
- The locale of the messages.
- Returns:
- An array list containing the number of messages processed, number of messages added, number of messages updated, number of messages deleted by the import, and a list of errors produced. The keys of the array list are processed, added, updated, and deleted, and errors.
- Authors:
- Peter Marklund
- Lars Pind
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::is_upgrade_backup_file (private)
lang::catalog::is_upgrade_backup_file file_path
Given a file path return 1 if the path represents a file with messages backed up from message catalog upgrade.
- Parameters:
- file_path (required)
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::last_sync_messages (private)
lang::catalog::last_sync_messages -package_key package_key \ -locale locale
For a certain package, and locale, return the messages in the database the last time catalog files and db were in sync. This is the message that we use as merge base during message catalog upgrades.
- Switches:
- -package_key (required)
- -locale (required)
- Returns:
- An array list with message keys as keys and messages as values.
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::message_backup_file_prefix (private)
lang::catalog::message_backup_file_prefix
The prefix used for files where we store old messages that were overwritten during message catalog upgrade.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::messages_in_db (private)
lang::catalog::messages_in_db -package_key package_key -locale locale
Return a list of all messages for a certain package and locale.
- Switches:
- -package_key (required)
- -locale (required)
- Returns:
- An array list with message keys as keys and messages as values.
- Author:
- Peter Marklund
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::package_catalog_dir (public)
lang::catalog::package_catalog_dir package_key
Return the catalog directory of the given package.
- Parameters:
- package_key (required)
- Author:
- Peter Marklund <peter@collaboraid.biz>
- Created:
- 18 October 2002
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- util__replace_temporary_tags_with_lookups
lang::catalog::package_delete (public)
lang::catalog::package_delete -package_key package_key
Unregister the I18N messages for the package.
- Switches:
- -package_key (required)
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- test_catalog_import_export
lang::catalog::package_has_files_in_locale_p (private)
lang::catalog::package_has_files_in_locale_p package_key locale
Return 1 if the given package has any catalog files for the given locale and 0 otherwise.
- Parameters:
- package_key (required)
- locale (required)
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- lang_package_has_files_in_locale_p
lang::catalog::parse (private)
lang::catalog::parse catalog_file_contents
Parse the given catalog file xml contents and return the data as an array. The array will contain the following keys:
package_key locale charset messages - An array-list with message keys as keys and the message texts as values. descriptions - An array-list with message keys as keys and the descriptions as values.
- Parameters:
- catalog_file_contents (required)
- Authors:
- Peter Marklund <peter@collaboraid.biz>
- Simon Carstensen <simon@collaboraid.biz>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- util__replace_temporary_tags_with_lookups
lang::catalog::read_file (private)
lang::catalog::read_file catalog_filename
Returns the contents of the given catalog file as a string reading the file with the charset given in the filename.
- Parameters:
- catalog_filename (required)
- The full path of the catalog file to read. The basename of the file should be on the form package_key.locale.charset.ending where ending is either cat or xml (i.e. dotlrn.en_US.iso-8859-1.xml or dotlrn.en_US.iso-8859-1.cat). The cat ending is for the deprecated tcl-based catalog files.
- Authors:
- Jeff Davis
- Peter Marklund <peter@collaboraid.biz>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- util__replace_temporary_tags_with_lookups
lang::catalog::translate (private)
lang::catalog::translate
Translates all untranslated strings in a message catalog from English into Spanish, French and German using Babelfish. NOTE: this proc is unmaintained. Quick way to get a multilingual site up and running if you can live with the quality of the translations.
Not a good idea to run this procedure if you have a large message catalog. Use for testing purposes only.
- Author:
- John Lowry <lowry@arsdigita.com>
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
lang::catalog::uninitialized_packages (private)
lang::catalog::uninitialized_packages
Return a list of keys for installed and enabled packages that do not have any message keys associated with them. This would suggest that either the package is not internationalized, or we have not yet imported the message keys for the package.
- Author:
- Peter Marklund
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.