[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]

Re: Nested slices and variables



On Sat, Feb 09, 2002 at 07:47:08PM +0100, Ghislaine Labouret wrote:
> When nesting languages slices into another one like this :
> 
> <en: <fr: français><en: english>>
> 
> the output is, as I expected :
> - nothing in the .fr file
> - "english" in the .en file
> 
> But, if the inside slices come from a variable, like this :
> 
> <set-var foo="<fr: français><en: english>">
> <en: <get-var foo>>
> 
> the output becomes this :
> - "français" in the .fr file
> - "françaisenglish" in the .en file
> 
> Is this a feature or a bug?

Good question ;)

Basically,
  <fr: francais><en: english>
is replaced during pass 2 by
  [LANG_FR:francais:LANG_FR][LANG_EN:english:LANG_EN]
which is splitted into several files by wml_p9_slice.
Now if you look into wml_p9_slice documentation, it is clear that

  %!slice -o UNDEF+LANG_EN:foo.en -o UNDEF+LANG_FR:foo.fr
  [LANG_EN:[LANG_FR:francais:LANG_FR][LANG_EN:english:LANG_EN]:LANG_EN:]

gives:

  === foo.en ===
  francaisenglish
  === foo.fr ===
  francais
 
But maybe there are other slices, so a better alternative is:

  %!slice -o (ALL-LANG_*)+LANG_EN:foo.en -o (ALL-LANG_*)+LANG_FR:foo.fr
  [LANG_EN:[LANG_FR:francais:LANG_FR][LANG_EN:english:LANG_EN]:LANG_EN:]

which gives the same output here.

As this is not what might be expected, wml::std::lang has been slightly
modified to use a language stack, and only output strings if it is not
already included inside another language slice.
So 
  <en: <fr: francais><en: english>>
is in fact replaced by
  [LANG_EN:english:LANG_EN]
because FR slice is skipped, and output is correct.

But with variable expansion,
  <set-var foo="<fr: français><en: english>">
  <en: <get-var foo>>
gives
  <set-var foo="[LANG_FR:français:LANG_FR][LANG_EN:english:LANG_EN]">
  [LANG_EN:[LANG_FR:français:LANG_FR][LANG_EN:english:LANG_EN]:LANG_EN]
and previous problems are back because WML does not know of nested
language slices.

As you see, this is only a workaround to hide problems to end users,
which is sometimes confusing.

You could use variables if their content is not expanded until it is
printed at the desired place, by replacing <set-var> tags by
<set-var-verbatim>.  This way, WML can detect nested slices again.

Another (much better) solution is to redefine slice selection: instead of
  %!slice -o LANG_FRuUNDEF:$(WML_SRC_BASENAME).html.fr -o LANG_ENuUNDEF:$(WML_SRC_BASENAME).html.en
write
  %!slice -o (LANG_FRuUNDEF)-LANG_*{FR}:$(WML_SRC_BASENAME).html.fr -o (LANG_ENuUNDEF)-LANG_*{EN}:$(WML_SRC_BASENAME).html.en
where `LANG_*{FR}' means union of all LANG_* slices except LANG_FR.
This is different from `LANG_*-LANG_FR', it's why a new operator was
needed.

I will change default slice selection to use this operator.

For those who like experimental and undocumented features,
  <lang:star:slice: (LANG_**uUNDEF)-LANG_*{**}:$(WML_SRC_BASENAME).html.* >
write the previous %!slice line.  Double stars are replaced by language
id in uppercase letters when they appear before the colon delimiter.
It has never been documented because I do not like this syntax, so feel
free to send improvements.

-- 
Denis Barbier
WML Maintainer
______________________________________________________________________
Website META Language (WML)                www.engelschall.com/sw/wml/
Official Support Mailing List                   sw-wml@engelschall.com
Automated List Manager                       majordomo@engelschall.com