Converting from unicode to ASCII

Paul Dupuis paul at researchware.com
Wed Sep 23 10:16:17 EDT 2020


On 9/22/2020 6:48 PM, J. Landman Gay via use-livecode wrote:
> I have a stack with an index. When a user clicks a line, a handler 
> uses the clicktext to create a file name which is always the clicktext 
> plus the ".livecode" extension. The stack is then downloaded from an 
> AWS server and displayed.
>
> We are now translating some stacks to other languages which require 
> unicode text. AWS recommends not using accented characters in file 
> names, so we need to translate the clicktext into plain ASCII.
>
> Is there a good way to do that without using a lookup table or 
> metadata? The file names doesn't need to make sense syntactically. For 
> example,
>
>    l’Académie française -> lAcademiefrancaise.livecode
>
> ...or similar, whatever works. The user will never see the file name.
>

You should probably use the same model as LiveCOde uses to match files 
names returned from the files(<path>"detailed-utf8") function:

urlEncode(textEncode(normalizeText(<name>,"NFC"),"utf8"))

Converts:
Russian-русский-Lipsum.docx

To:
Russian-%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9-Lipsum.docx

For what your doing, I think that using:

urlEncode(textEncode(<accentedListName>,"utf8")) -> gets <filename>

and

textDecode(urlDecode(<filename>),"utf8") -> gets <accentedListName>

should be enough.





More information about the use-livecode mailing list