Hi Charles,
ok, so this breaks down into two parts;
a) how to inject a file into a form, as a form-field. and
b) how to make this filename a variable.
the first part is easy enough -
a) Create a form field of type "display"
b) Set the "text field" to say '<!-- Net:f:english.htm -->'
and
c) (importantly) tick on Allow xHtml.
(see attached pic a1.png).
The second question is more interesting because you have a number of possible options here. You could
a) translate the filename before it is used
b) set some tag, which is then translated by the Translate method or
c) translate the filename as it is interpreted (ie when the file is loaded)
I'll detail all 3, you can decide which one to use.
1. Translate the name in the form, before the tag is added to the form.
If you look at the generated code, and search for english.htm, you'll find the following block;
If Not (1=0)
! --- DISPLAY --- or ---- BUTTON
loc:javascript = 'data-do="onclick" id="incfile"'
packet = clip(packet) & |
p_web.Translate('<!-- Net:f:english.htm -->',1) & |
'<13,10>'
do SendPacket
It's not difficult to make the '<!-- Net:f:english.htm -->' an expression.
a) Create a local variable, loc:snippet.
b) Replace '<!-- Net:f:english.htm -->' with loc:snippet in the form field template settings.
c) In the embed, right before it is used, set loc:snippet to either say
'<!-- Net:f:english.htm -->' or '<!-- Net:f:spanish.htm -->' or whatever.
Aside: The local variable is safe in this case because it is set and then used immediately, in the same block of code.
2. Translate the name using the Translate method.
As you can see the call in the above code is
p_web.Translate('<!-- Net:f:english.htm -->',1)
If you replaced '<!-- Net:f:english.htm -->' with say 'xSnippet1'
Then your translation mechanism could translate xSnippet1 into
'<!-- Net:f:english.htm -->' or (say) '<!-- Net:f:spanish.htm -->'
If I was going to do this a lot I might be tempted to make a sort of standard. For example calling the file something.eng.htm then the translate method only needs to look for .eng. and replace with .esp. say, without knowing the rest of the filename (or indeed caring about it).
If you were going to do a lot of these snippets then this "generic replacement" seems like the easiest way to go, while making the form code easy to understand (because when editing the form you can at least immediately see the default file which will be used there.)
3. Translate the tag when the file is loaded.
Both of the above techniques expose one problem - if the alternate language version of the file does not exist then the user sees nothing. It does not "fall back" on the original english version.
A somewhat more sophisticated approach takes the idea from number 2 (generic names) and do the translation at the point when the file is loaded. Imagine that we have 2 files welcome.eng.htm and welcome.esp.htm. In the program code, for the form display field, you simply include '<!-- Net:f:welcome.eng.htm -->'
If you follow the code in netweb.clw, you'll see that the loading of the file is done by the WebHandler._SendFile method. This method takes, as its first parameter, the name of the file to send. So you could embed something like the following in the WebHandler procedure, _SendFile method, before the parent call. This sample code uses StringTheory to simplify the string handling, but you can use normal Clarion string handling if you prefer;
str stringtheory
code
str.setvalue(p_FileName)
if str.instring('.eng.')
str.replace('.eng.',self.GSV('languageprefix'))
if exists(str.GetValue())
PARENT._SendFile(str.GetValue(),p_header)
return
end
end
Obviously the session value of languageprefix contains the language code for the current user.
The main advantage of this approach is that it's completely generic (it'll work on any number of files) and if the translation is missing it falls back on the originally included file. Plus the form contains the actual file name (of the english version anyway) which makes the form easier to maintain.
cheers
Bruce
[attachment deleted by admin]