Re: Pico, how to translate function result?
On Tue, Jul 08, 2008 at 04:09:04PM +0200, Jon Kleiser wrote: > Almost. This is better: > > (de translate (Txt) > (if (val (car (idx '*Uni Txt))) @ Txt) ) or even: (de translate (Txt) (if (idx '*Uni Txt) (val (car @)) Txt ) ) ;-) Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Pico, how to translate function result?
Hi Alex, Hi Jon, do you do if the text to be translated is the result of some function? This doesn't seem to work: ,(someTextBasedOn X Y Z) Yes, in this context the comma makes only sense immediately before the transient symbol. The comma read macro does nothing else than putting the following expression into a global idx tree (i.e. into '*Uni'). The 'locale' function then iterates over this tree, and replace the values of all symbols with the new translated values. If you put a list into '*Uni', like in the example above, 'locale' cannot process it. Thus, a function can only return a transient symbol (for which hopefully then a translation exists). You could do (de foo () .. (list ,"My new string" X Y Z) ) Then, if "My new string" exists in the "loc/xx" file, it will behave as expected. But perhaps you intend to build the string dynamically? Well, this is possible, though I never tested it before. Let's try it: : (locale "DE" "de") As an example, I take the string "Numeric input expected". It has a standard translation: : (val ,"Numeric input expected") -> "Zahleneingabe erforderlich" Now, to look up the string dynamically, we can do the following: : (val (car (idx '*Uni (pack "Numeric " "input" " expected" -> "Zahleneingabe erforderlich" So, in summary, your function could look like this: (de foo () .. (list (car (idx '*Uni (pack "My new" " string"))) X Y Z ) ) This should do it. Thanks! This was what I needed: (de translate (Txt) (val (car (idx '*Uni Txt))) ) Almost. This is better: (de translate (Txt) (if (val (car (idx '*Uni Txt))) @ Txt) ) /Jon -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Pico, how to translate function result?
Hi Alex, Hi Jon, do you do if the text to be translated is the result of some function? This doesn't seem to work: ,(someTextBasedOn X Y Z) Yes, in this context the comma makes only sense immediately before the transient symbol. The comma read macro does nothing else than putting the following expression into a global idx tree (i.e. into '*Uni'). The 'locale' function then iterates over this tree, and replace the values of all symbols with the new translated values. If you put a list into '*Uni', like in the example above, 'locale' cannot process it. Thus, a function can only return a transient symbol (for which hopefully then a translation exists). You could do (de foo () .. (list ,"My new string" X Y Z) ) Then, if "My new string" exists in the "loc/xx" file, it will behave as expected. But perhaps you intend to build the string dynamically? Well, this is possible, though I never tested it before. Let's try it: : (locale "DE" "de") As an example, I take the string "Numeric input expected". It has a standard translation: : (val ,"Numeric input expected") -> "Zahleneingabe erforderlich" Now, to look up the string dynamically, we can do the following: : (val (car (idx '*Uni (pack "Numeric " "input" " expected" -> "Zahleneingabe erforderlich" So, in summary, your function could look like this: (de foo () .. (list (car (idx '*Uni (pack "My new" " string"))) X Y Z ) ) This should do it. Thanks! This was what I needed: (de translate (Txt) (val (car (idx '*Uni Txt))) ) I still have a lot to learn! ;-) /Jon -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: Pico, how to translate function result?
Hi Jon, > do you do if the text to be translated is the result of some function? > This doesn't seem to work: > > ,(someTextBasedOn X Y Z) Yes, in this context the comma makes only sense immediately before the transient symbol. The comma read macro does nothing else than putting the following expression into a global idx tree (i.e. into '*Uni'). The 'locale' function then iterates over this tree, and replace the values of all symbols with the new translated values. If you put a list into '*Uni', like in the example above, 'locale' cannot process it. Thus, a function can only return a transient symbol (for which hopefully then a translation exists). You could do (de foo () .. (list ,"My new string" X Y Z) ) Then, if "My new string" exists in the "loc/xx" file, it will behave as expected. But perhaps you intend to build the string dynamically? Well, this is possible, though I never tested it before. Let's try it: : (locale "DE" "de") As an example, I take the string "Numeric input expected". It has a standard translation: : (val ,"Numeric input expected") -> "Zahleneingabe erforderlich" Now, to look up the string dynamically, we can do the following: : (val (car (idx '*Uni (pack "Numeric " "input" " expected" -> "Zahleneingabe erforderlich" So, in summary, your function could look like this: (de foo () .. (list (car (idx '*Uni (pack "My new" " string"))) X Y Z ) ) This should do it. Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Pico, how to translate function result?
Hi, I thought I had done this before, but now I don't remember how ... ;-) If you want to translate a certain string, you can do like this ,"This works fine." and get a translation, depending on the use of "(locale ...)". But what do you do if the text to be translated is the result of some function? This doesn't seem to work: ,(someTextBasedOn X Y Z) /Jon -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]