rejetto forum

Macros

Mars · 231 · 114837

0 Members and 1 Guest are viewing this topic.

Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
I would leave special:strings how it is so you can use a strings table without an external file, but if using an external file I would use 'from table' instead.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13438
    • View Profile
{{!}} is a special case of {{from table}}
but for localization we need to use ! because it's much shorter.
with fro, table you have to specify the name of the table also. every time.


Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1935
    • View Profile
    • RAWR-Designs
I figured it out! The break is coming from the Diff Template value of [theme], so sections in Diff Template have a break after them!

The {{load}} macro i am still working with... I think we need the ability to fire a macro in [special:strings], cause even if u wanted to import some strings from another section, you need to fire {{$section}}.
« Last Edit: January 18, 2008, 09:25:45 AM by That_Stevens_Guy »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13438
    • View Profile
I figured it out! The break is coming from the Diff Template value of [theme], so sections in Diff Template have a break after them!

this means it is not a bug. Right?

Quote
The {{load}} macro i am still working with... I think we need the ability to fire a macro in [special:strings], cause even if u wanted to import some strings from another section, you need to fire {{$section}}.

from next beta, try using {{load|yourfile|special:string}}
this will load the file in {{^special:string}} that is a variable, not the section.
That's because {{!asd}} will search asd in several places, in this order:
in variable special:strings
in section special:strings
in the optional parameter
and if it is not found anyhwere, "asd" itself is returned
« Last Edit: January 20, 2008, 05:31:13 PM by rejetto »


Offline TSG

  • Operator
  • Tireless poster
  • *****
    • Posts: 1935
    • View Profile
    • RAWR-Designs
I figured it out! The break is coming from the Diff Template value of [theme], so sections in Diff Template have a break after them!

this means it is not a bug. Right?

No it means it IS a bug, the main template doesnt have breaks after sections, why should it be different for Diff template?

I will try this method when next build is released.
« Last Edit: January 20, 2008, 05:55:07 PM by That_Stevens_Guy »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2055
    • View Profile
Quote
from next beta, try using {{load|yourfile|special:string}}
this will load the file in {{^special:string}} that is a variable, not the section.

one question

when using {{load|yourfirstfile|special:string}} before {{load|yoursecondfile|special:string}}

Is yoursecondfile append to {{!special:string}} or rewrite over {{!special:string}} ?

an option can be added
{{load|yourfile|special:string|sectionname}}

by example in yourfile are some sections

[special:strings]
mytext=english

[special:stings_fr]
mytext=français

[special:stings_it]
mytext=Italiano

using {{load|yourfile|special:strings|special:strings_fr}} load only content of section [special:strings_fr] from yourfile,  or [special:strings] if par[3] is not specified

2e question

{{load|yourfile|special:string}}  i think that only section [special:strings] into yourfile must be include, not all content of the file

It is to offers more possibility to load with same syntax others sections as [special:begin] included in variable {{!special:begin}}
{{load|yourfile|special:begin}}
That's because {{!asd}} will search asd in several places, in this order:
in section special:begin       {{set|myvar|text}}
in variable special:begin       {{set|myvar|Overloaded Text }}  can replace text defined above for a specific usage
(dans cet ordre pour une possible possible surcharge  des définitions de variables ou macros)
{{load|yourfile|special:begin|sectionname}}
it is possible with some restriction

« Last Edit: January 20, 2008, 10:26:05 PM by mars »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2055
    • View Profile
{{FROM TABLE|...}
how to use it?? ??

désolé si je suis passé à coté de la réponse dans un autre post

« Last Edit: January 20, 2008, 10:46:05 PM by mars »


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2055
    • View Profile

Quote
{from table|table/variable|string id}}

A concrete example would be welcome


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
{{set|example|
foo=this is an example
foo2=this is another example
/set}}

{{from table|example|foo}} will return "this is an example"

{{from table|example|foo2}} will return "this is another example"


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13438
    • View Profile
when using {{load|yourfirstfile|special:string}} before {{load|yoursecondfile|special:string}}
Is yoursecondfile append to {{!special:string}} or rewrite over {{!special:string}} ?

it's overwritten

Quote
an option can be added
{{load|yourfile|special:string|sectionname}}

yes, but you can already do it using {{set|special:string|{{$sectionname|yourfile}}/set}}
We'll do it if we see any need of it.

Quote
2e question
{{load|yourfile|special:string}}  i think that only section [special:strings] into yourfile must be include, not all content of the file

ditto. you can already do it.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13438
    • View Profile
No it means it IS a bug, the main template doesnt have breaks after sections, why should it be different for Diff template?
I will try this method when next build is released.

found the bug and fixed :)
the problem were not diff templates, but just "the last section of any template"


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2055
    • View Profile
Quote
Quote from: mars on 20 January 2008, 23:14:54
when using {{load|yourfirstfile|special:string}} before {{load|yoursecondfile|special:string}}
Is yoursecondfile append to {{!special:string}} or rewrite over {{!special:string}} ?


it's overwritten


Quote
an option can be added
{{load|yourfile|special:string|sectionname}}


yes, but you can already do it using {{set|special:string|{{$sectionname|yourfile}}/set}}
We'll do it if we see any need of it.

Rejetto ,You forgot to clarify  ;)
Quote
from next beta, try using {{load|yourfile|special:string}}
this will load the file in {{^special:string}} that is a variable, not the section.
That's because {{!asd}} will search asd in several places, in this order:
in variable special:strings
in section special:strings
in the optional parameter
and if it is not found anyhwere, "asd" itself is returned
{{set|special:string|{{$sectionname|yourfile}}/set}}
{{set append|special:string|{{$sectionname|yoursecondfile}}/set}}

It completes your two answers



Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2055
    • View Profile
for each | A | B1 | B2 | B3 | .....| Bn | C

repeats C by replacing variable {{^A}} with every value from B1 to  Bn  (n>=1)

i have create this macro by example to replace more than one substring in a string
Quote

{{for each| A | 5 | 2 | 3 | 8 | 6 | 1 | 0 | {{\   ({{^A}}) / /}} }}

result is  (5) /  (2) /  (3) /  (8) /  (6) /  (1) /  (0) /



code source pour HFS
Quote
if pars.count < 3 then exit; // from here, only macros with at least 3 parameters

 if name ='for each' then
    foreach();


.........

 procedure foreach();
  var
    j, n : integer;
    theVar, code: string;
  begin
  try
    j:=max(1,pars.count-2);
    code:=par(pars.count-1);
    if code=''then exit;
    code:=dequote(code);
    theVar:=format('{{^%s}}',[p]);
    with TfastStringAppend.create do
      try
        for n:= 1 to j do
          begin
          append(xtpl(code, [theVar, par(n)]));
          end;
        result:=reset();
      finally free end;
    if assigned(md.cd) then
      md.cd.vars.values[p]:=intToStr(j);
  except end;
  end; // foreach

« Last Edit: January 29, 2008, 08:54:15 AM by mars »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2055
    • View Profile
replace | A1 | B1 | A2 | A2 | B2 | ....... | An | Bn | C

returns C with every Ax replaced with Bx

code source pour HFS
Quote
  if name = 'replace' then
    replace();
.....
  procedure replace();
  var
    i: integer;
  begin
    p:=par(pars.Count -1);
    i:=0;
    while (i < pars.count-1) and not (i = pars.count-2) do
      begin
      p:=xtpl(p, [par(i), par(i+1)]);
      inc(i,2);
      end;
    result:=p;
  end; // replace


{{replace| 2|two | 3|three | 4|four | 7|seven | 9|nine | 0 1 2 3 4 5 6 7 8 9}}
{{replace| 2|two | 3|three | 4|four | 7|seven | 9|nine | 0| 0 1 2 3 4 5 6 7 8 9}}

result is 0 1 two three four 5 6 seven 8 nine
« Last Edit: January 29, 2008, 08:55:19 AM by mars »