So I guess it turns out I did exactly the thing I was complaining about at the beginning of my post...
As a quick recap, we were pulling data from an external, homemade application, so this may need some tweaking in order for it to work for you. This function lives in a Text Component that is paired with our Care Plan form, which took some hunting to ultimately find and figure out (I don't get the point of Text Components, but if someone wants to proselytize, please do!) Finally, our solution was weird, in that the ASCII assignments for the special characters were not actually represented in ASCII... So you may need to do a little leg work to determine what the incoming characters are.
Here was our ultimate solution:
{
fn eng2span(text) {
local CPText1 = ""
local convText = ""
local textArray = ""
local pos = ""
/*These variables are all the special characters turned into ASCII values*/
local char_a = numtoascii(225)
local char_e = numtoascii(233)
local char_i = numtoascii(237)
local char_n = numtoascii(241)
local char_o = numtoascii(243)
local char_u = numtoascii(250)
for i = 1, i <= 2001, i = i + 1 do
local replaceChar = ""
pos = match(text, numtoascii(195))
if pos == 0 then
break
else
endif
text = remove(text, pos, 1)
/*These case statements all search for broken characters, turn them to ASCII codes (you see they're all negative...) and then swaps them for the variables assigned above*/
cond
case asciitonum(sub(text, pos, 1)) == -95 replaceChar = char_a
case asciitonum(sub(text, pos, 1)) == -87 replaceChar = char_e
case asciitonum(sub(text, pos, 1)) == -83 replaceChar = char_i
case asciitonum(sub(text, pos, 1)) == -79 replaceChar = char_n
case asciitonum(sub(text, pos, 1)) == -77 replaceChar = char_o
case asciitonum(sub(text, pos, 1)) == -70 replaceChar = char_u
else
continue
endcond
text = set(text, pos, replaceChar)
endfor
for i = 1, i <= 2001, i = i + 1 do
pos = match(text, numtoascii(194))
if pos == 0 then
break
else
endif
text = remove(text, pos, 1)
endfor
return text
}
}
We called this function in the other functions that we use to pull the text from the the external program and to display it in the text translation. I hope this helps! Please let me know if you, or anyone else, has any questions. This was hard work, and hopefully this can be used to help make that work easier for anyone else.
Posted : April 8, 2019 5:55 am