Index: openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl,v diff -u -r1.24 -r1.25 --- openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl 15 Oct 2003 08:23:50 -0000 1.24 +++ openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl 15 Oct 2003 12:37:58 -0000 1.25 @@ -121,7 +121,6 @@ } ad_proc lang::util::replace_temporary_tags_with_lookups { - {-catalog_file_path ""} file_list } { Modify the given adp or tcl files by replacing occurencies of @@ -137,9 +136,6 @@ file per default) of the package that the files belong to, the database is not accessed in any way. - @param catalog_file_path The fully qualified path of the catalog file. - If not provided the catalog file for the en_US locale will be - used, i.e. $package_root/catalog/$package_key.en_US.ISO-8859-1.xml. @param file_list A list of paths to adp or tcl files to do replacements in. The paths should be relative to [acs_root_dir]. All files must belong to the same package. @@ -153,17 +149,20 @@ return } - # Read messages from any existing catalog file - # Get the package the files belong to - set first_file [lindex $file_list 0] - + # Get package_key + set first_file [lindex $file_list 0] if { ![regexp {/?packages/([^/]+)/} $first_file match package_key] } { error "lang::util::replace_temporary_tags_with_lookups - Could not extract package_key from file $first_file" } - set catalog_dir "[acs_root_dir]/packages/$package_key/catalog" - if { [empty_string_p $catalog_file_path] } { - set catalog_file_path "$catalog_dir/$package_key.en_US.ISO-8859-1.xml" - } + + # Always create new keys in en_US + set locale "en_US" + + # Read messages from any existing catalog file + set catalog_file_path [lang::catalog::get_catalog_file_path \ + -package_key $package_key \ + -locale $locale \ + -charset [ad_locale charset $locale]] if { [file exists $catalog_file_path] } { set catalog_file_contents [lang::catalog::read_file $catalog_file_path] array set catalog_array [lang::catalog::parse $catalog_file_contents] @@ -307,8 +306,7 @@ } # Generate a new catalog file - array set catalog_file [apm_parse_catalog_path $catalog_file_path] - lang::catalog::export_package_to_files -locales [list $catalog_file(locale)] $catalog_file(package_key) + lang::catalog::export_package_to_files -locales [list $locale] $package_key } return $number_of_replacements Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 14 Oct 2003 07:39:28 -0000 1.8 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 15 Oct 2003 12:37:58 -0000 1.9 @@ -43,77 +43,90 @@ @author Peter Marklund (peter@collaboraid.biz) @creation-date 18 October 2002 } { - # The files involved in the test - set test_dir [lang::test::get_dir] - set catalog_dir [lang::catalog::package_catalog_dir acs-lang] - set catalog_file "${catalog_dir}/acs-lang.xxx_xx.ISO-8859-1.xml" - set backup_file_suffix ".orig" - set catalog_backup_file "${catalog_file}${backup_file_suffix}" - regexp {^.*(packages/.*)$} $test_dir match test_dir_rel - set tcl_file "${test_dir_rel}/test-message-tags.tcl" - set tcl_backup_file "${tcl_file}${backup_file_suffix}" - - # The test messages to use for the catalog file - array set messages_array [list key_1 text_1 key_2 text_2 key_3 text_3] - - # Write the test tcl file - set tcl_file_id [open "[acs_root_dir]/$tcl_file" w] - set new_key_1 "_" - set new_text_1 "Auto Key" - set new_key_2 "key_1" - set new_text_2 "text_1_different" - set new_key_3 "key_1" - set new_text_3 "$messages_array(key_1)" - puts $tcl_file_id "# The following key should be auto-generated and inserted - # <#${new_key_1} ${new_text_1}#> - # - # The following key should be made unique and inserted - # <#${new_key_2} ${new_text_2}#> - # - # The following key should not be inserted in the message catalog - # <#${new_key_3} ${new_text_3}#>" - close $tcl_file_id - - # Write the catalog file - lang::catalog::export_messages_to_file $catalog_file [array get messages_array] - - # Replace message tags in the tcl file and insert into catalog file - lang::util::replace_temporary_tags_with_lookups -catalog_file_path $catalog_file $tcl_file - - # Read the contents of the catalog file - array set catalog_array [lang::catalog::parse [lang::catalog::read_file $catalog_file]] - array set updated_messages_array [lindex [array get catalog_array messages] 1] - - # Assert that the old messages are unchanged - foreach old_message_key [array names messages_array] { - aa_true "old key $old_message_key should be unchanged" [string equal $messages_array($old_message_key) \ - $updated_messages_array($old_message_key)] + aa_run_with_teardown \ + -rollback \ + -test_code { + + # The files involved in the test + set test_dir [lang::test::get_dir] + set catalog_dir [lang::catalog::package_catalog_dir acs-lang] + set catalog_file "${catalog_dir}/acs-lang.xxx_xx.ISO-8859-1.xml" + set backup_file_suffix ".orig" + set catalog_backup_file "${catalog_file}${backup_file_suffix}" + regexp {^.*(packages/.*)$} $test_dir match test_dir_rel + set tcl_file "${test_dir_rel}/test-message-tags.tcl" + set tcl_backup_file "${tcl_file}${backup_file_suffix}" + + # The test messages to use for the catalog file + array set messages_array [list key_1 text_1 key_2 text_2 key_3 text_3] + + # Write the test tcl file + set tcl_file_id [open "[acs_root_dir]/$tcl_file" w] + set new_key_1 "_" + set new_text_1 "Auto Key" + set new_key_2 "key_1" + set new_text_2 "text_1_different" + set new_key_3 "key_1" + set new_text_3 "$messages_array(key_1)" + puts $tcl_file_id "# The following key should be auto-generated and inserted + # <#${new_key_1} ${new_text_1}#> + # + # The following key should be made unique and inserted + # <#${new_key_2} ${new_text_2}#> + # + # The following key should not be inserted in the message catalog + # <#${new_key_3} ${new_text_3}#>" + close $tcl_file_id + + # Write the catalog file + lang::catalog::export_messages_to_file $catalog_file [array get messages_array] + + # We need to force the API to use the test catalog file + aa_stub lang::catalog::get_catalog_file_path " + return $catalog_file + " + + # Replace message tags in the tcl file and insert into catalog file + lang::util::replace_temporary_tags_with_lookups $tcl_file + + aa_unstub lang::catalog::get_catalog_file_path + + # Read the contents of the catalog file + array set catalog_array [lang::catalog::parse [lang::catalog::read_file $catalog_file]] + array set updated_messages_array [lindex [array get catalog_array messages] 1] + + #error "catalog_array=[array get catalog_array] updated_messages_array=[array get updated_messages_array]" + + # Assert that the old messages are unchanged + foreach old_message_key [array names messages_array] { + aa_true "old key $old_message_key should be unchanged" [string equal $messages_array($old_message_key) \ + $updated_messages_array($old_message_key)] + } + + # Check that the first new key was autogenerated + aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1] + + # Check that the second new key was made unique and inserted + aa_true "check key made unique" [string equal $updated_messages_array(${new_key_2}_1) $new_text_2] + + # Check that the third key was not inserted + aa_true "third key not inserted" [string equal [lindex [array get updated_messages_array $new_key_3] 1] \ + $messages_array($new_key_3)] + + # Check that there are no tags left in the tcl file + set tcl_file_id [open "[acs_root_dir]/$tcl_file" r] + set updated_tcl_contents [read $tcl_file_id] + close $tcl_file_id + aa_true "tags in tcl file replaced" [expr [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0] + + # Delete the catalog files + file delete $catalog_backup_file + file delete $catalog_file + + # Delete the tcl files + file delete "[acs_root_dir]/$tcl_file" + file delete "[acs_root_dir]/$tcl_backup_file" } - - # Check that the first new key was autogenerated - ns_log Notice "auto key compare \"$updated_messages_array(Auto_Key)\" - \"$new_text_1\"" - aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1] - - # Check that the second new key was made unique and inserted - aa_true "check key made unique" [string equal $updated_messages_array(${new_key_2}_1) $new_text_2] - - # Check that the third key was not inserted - aa_true "third key not inserted" [string equal [lindex [array get updated_messages_array $new_key_3] 1] \ - $messages_array($new_key_3)] - - # Check that there are no tags left in the tcl file - set tcl_file_id [open "[acs_root_dir]/$tcl_file" r] - set updated_tcl_contents [read $tcl_file_id] - close $tcl_file_id - aa_true "tags in tcl file replaced" [expr [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0] - - # Delete the catalog files - file delete $catalog_backup_file - file delete $catalog_file - - # Delete the tcl files - file delete "[acs_root_dir]/$tcl_file" - file delete "[acs_root_dir]/$tcl_backup_file" } aa_register_case util__get_hash_indices {