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.6 -r1.7
--- openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl 23 Oct 2002 11:48:17 -0000 1.6
+++ openacs-4/packages/acs-lang/tcl/lang-util-procs.tcl 28 Oct 2002 12:32:45 -0000 1.7
@@ -61,7 +61,6 @@
@author Peter marklund (peter@collaboraid.biz)
} {
-
set regexp_pattern {(?:^|[^\\])(\#[-a-zA-Z0-9_:\.]+\#)}
return [get_regexp_indices $multilingual_string $regexp_pattern]
}
@@ -319,7 +318,12 @@
# Attempt a message lookup
set message_value [_ [ad_locale request locale] $message_key]
- regsub $replacement_string $subst_string $message_value subst_string
+ # Replace the string
+ # LARS: We don't use regsub here, because regsub interprets certain characters
+ # in the replacement string specially.
+ set subst_string [string range $string_with_hashes 0 [expr [lindex $item_idx 0]-1]]
+ append subst_string $message_value
+ append subst_string [string range $string_with_hashes [expr [lindex $item_idx 1]+1] end]
}
return $subst_string
@@ -390,8 +394,24 @@
set key "lt_[string range $key 0 20]"
}
return $key
- }
+ }
+ ad_proc -private convert_adp_variables_to_percentage_signs { text } {
+ Convert ADP variables to percentage_signs - that is the variable
+ notation used in acs-lang messages.
+
+ @author Peter Marklund
+ } {
+ # substitute array variable references
+ # loop to handle the case of adjacent variable references, like @a@@b@
+ while {[regsub -all [template::adp_array_variable_regexp] $text {\1%\2.\3%} text]} {}
+
+ # substitute simple variable references
+ while {[regsub -all [template::adp_variable_regexp] $text {\1%\2%} text]} {}
+
+ return $text
+ }
+
ad_proc -public replace_adp_text_with_message_tags {
file_name
mode
@@ -410,11 +430,19 @@
- 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.
- 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.
+ @param file_name The name of the adp file to do replacements in.
+ @param mode Either report or write.
+ @param keys 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.
+ @return 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.
+
@author Christian Hvid
+ @author Peter Marklund
@author Jeff Davis
} {
@@ -441,21 +469,24 @@
if {![regexp {(^[^<]*?)(<.*)$} $s match text s x]} {
set text $s
set s {}
- }
+ }
+
+ regsub -all {@[a-zA-Z0-9_\.]+@} $text "" text_wo_variables
# make sure the string is non empty and contains at least one letter.
if {![empty_string_p $text]
- && ![string is space $text]
+ && ![string is space $text_wo_variables]
&& [string match -nocase {*[A-Z]*} $text]
- && ![regexp {^\s*@[A-Za-z_.-]*@\s*$} $text]
- && ![string match {* *} $text]
- && ![string match {*@*} $text]
&& ![string match {*\#*} $text]
&& ![string match {*\{*} $text]
&& ![string match {*\}*} $text]
&& [string length $text] > 1
} {
regexp {^(\s*)(.*?)(\s*)$} $text match lead text lag
+
+ set text_w_percentages [convert_adp_variables_to_percentage_signs $text]
+
+ ns_log Notice "PM: text $text text_w_percentages $text_w_percentages"
if { $mode == "report" } {
# create a key for the text
@@ -464,13 +495,31 @@
lappend report [list $key "[string range [remove_gt_lt $out$lead] end-20 end]$text[string range [remove_gt_lt $lag$s] 0 20]
" ]
} else {
- if { [lindex $keys $n] != "" } {
- lappend report [list [lindex $keys $n] "[string range [remove_gt_lt $out$lead] end-20 end]$text[string range [remove_gt_lt $lag$s] 0 20]
" ]
- append out "$lead<\#[lindex $keys $n] $text\#>$lag"
+ # Write mode
+ if { [llength $keys] != 0} {
+ # Use keys supplied
+ if { [lindex $keys $n] != "" } {
+ # Use supplied key
+ set write_key [lindex $keys $n]
+ } else {
+ # The supplied key for this index is empty so leave the text untouched
+ set write_key ""
+ }
} else {
+ # No keys supplied - autogenerate a key
+ set write_key [suggest_key $text]
+ }
+
+ if { ![empty_string_p $write_key] } {
+ # Write tag to file
+ lappend report [list ${write_key} "[string range [remove_gt_lt $out$lead] end-20 end]$text[string range [remove_gt_lt $lag$s] 0 20]
" ]
+
+ append out "$lead<\#${write_key} $text_w_percentages\#>$lag"
+ } else {
+ # Leave the text untouched
lappend garbage "[string range [remove_gt_lt $out$lead] end-20 end]$text [string range [remove_gt_lt $lag$s] 0 20]
"
append out "$lead$text$lag"
- }
+ }
}
incr n
@@ -522,6 +571,39 @@
return [list $report $garbage]
}
+ ad_proc -public 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.
+
+ @author Lars Pind (lars@collaboraid.biz)
+ @create-date October 24, 2002
+
+ @return 1 if translator mode is enabled, 0 otherwise.
+
+ @see lang::util::translator_mode_set
+ } {
+ return [ad_get_client_property -default 0 acs-lang translator_mode_p]
+ }
+
+ ad_proc -public translator_mode_set {
+ translator_mode_p
+ } {
+ Sets whether translator mode is enabled for this session or
+ not.
+
+ @author Lars Pind (lars@collaboraid.biz)
+ @create-date October 24, 2002
+
+ @param translator_mode_p 1 if you want translator mode to be enabled, 0 otherwise.
+
+ @see lang::util::translator_mode_p
+ } {
+ ad_set_client_property acs-lang translator_mode_p $translator_mode_p
+ }
+
+
}
#####