|
[Solved] About Rainlendar_SetItemValue() 2 Years, 3 Months ago
|
|
There is a small problem, I have a .lua file use the following code:
| Code: |
sTime = os.date("%x %a")
Rainlendar_SetItemValue("LunarCal", "LunarCal.info", "text", "今日情報:" .. sTime .. "\n" .. todaymsg1)
|
If the file is set to ANSI, it works fine(a),
If the file is set to UTF-8, it will not show(b), but Rainlendar_Message (sTime, 0) is normal display(c)
I found all the time-format that display with local language can not be showed.
How can I display properly using the UTF-8 encoded file??
Thank!!
|
|
|
|
Last Edit: 2013/03/06 12:45 By anoob.
I couldn't speak English! This skin released to Customize.org(Do you want it? Click Picture) Please contact me if interested: jhg5702@gmail.com

|
|
|
Re:About Rainlendar_SetItemValue() 2 Years, 3 Months ago
|
|
When i was mading a Maya calendar from a Maya font, i need to use Unicode values above 63000. Finding on the web i finally found this:
"The proper way to convert between UCS-4 and UTF-8 is to use bitmask (and, or) and bitshift operations. But if you would like to convert only a couple of characters by hand or if your program development environment (scripting language) does not support bit operations, then integer division and multiplication can be used as follows."
Because i didn't want to lose time searching for how to do the bitshift operations i use the mathematical way:
This will be valid if the dec value is between 2048 and 65535 (UTF-8 is 3 bytes long)
| Code: |
function UCS4_UTF8(dec)
a = 224 + (math.floor(dec / 4096))
b = 128 + (math.floor(dec / 64) % 64)
c = 128 + (dec % 64)
return string.char(a, b, c)
end
|
EDIT: This would be the full converter code from UTF-32 to UTF-8:
| Code: |
function UTF32_UTF8(dec)
if (dec < 128) then
a = dec
return string.char(a)
elseif (dec >= 128 and dec <= 2047) then
a = 192 + (math.floor(dec / 64))
b = 128 + (dec % 64)
return string.char(a, b)
elseif (dec >=2048 and dec <= 65535) then
a = 224 + (math.floor(dec / 4096))
b = 128 + (math.floor(dec / 64) % 64)
c = 128 + (dec % 64)
return string.char(a, b, c)
elseif (dec >= 65536 and dec <= 2097151) then
a = 240 + (math.floor(dec / 262144))
b = 128 + (math.floor(dec / 4096) % 64)
c = 128 + (math.floor(dec / 64) % 64)
d = 128 + (dec % 64)
return string.char(a, b, c, d)
elseif (dec >= 2097152 and dec <= 67108863) then
a = 248 + (math.floor(dec / 16777216))
b = 128 + (math.floor(dec / 262144) % 64)
c = 128 + (math.floor(dec / 4096) % 64)
d = 128 + (math.floor(dec / 64) % 64)
e = 128 + (dec % 64)
return string.char(a, b, c, d, e)
elseif (dec >= 67108864 and dec <= 2147483647) then
a = 252 + (math.floor(dec / 1073741824))
b = 128 + (math.floor(dec / 16777216) % 64)
c = 128 + (math.floor(dec / 262144) % 64)
d = 128 + (math.floor(dec / 4096) % 64)
e = 128 + (math.floor(dec / 64) % 64)
f = 128 + (dec % 64)
return string.char(a, b, c, d, e, f)
end
end
|
|
|
|
|
Last Edit: 2011/02/04 06:59 By Jorge_Luis.Reason: Full converter code
|
|
|
Re: About Rainlendar_SetItemValue() 2 Years, 3 Months ago
|
|
|
I at least can use the Rainlendar_SetItemValue() to display some Chinese characters in a text element. Can you attach a full example of this?
|
|
Rainy
Moderator
Posts: 5367
|
|
|
|
|
Re:About Rainlendar_SetItemValue() 2 Years, 3 Months ago
|
|
To Jorge_Luis:
Sorry, i can not understand what you say.
To all guys:
i think the real question is about the code os.date("%x %a")
in English OS it display "4/2/2011 Fri"(maybe),
in my pc(Chinese OS) it display "2011/2/4 星期五"
if i only write sTime = os.date("%x"), it work fine
but if i write sTime = "今日情報:" .. os.date("%x %a"), it can not show.
this issue happen on Rainlendar_Message() too.
i posted the skin that include this issue on customize.org/rainlendar/skins/79993
you can download it to try.
thank!!
|
|
|
|
Last Edit: 2011/02/04 13:29 By anoob.
I couldn't speak English! This skin released to Customize.org(Do you want it? Click Picture) Please contact me if interested: jhg5702@gmail.com

|
|
|
Re:About Rainlendar_SetItemValue() 2 Years, 3 Months ago
|
|
EDIT/UPDATE: I'm not sure of the next text. Is writed before this. I got totally confused because in the forum i can't see the Unicode fonts, only the Unicode values. My native language is Spanish, with ISO-8859-1 i've got all i need. So i don't know if the problem are the Unicode values or... well... i'm speechless.
sTime = "今日情報:" .. os.date("%x %a")
Did you try to remove ":" from the string? I see some CJK glyphs without this last character, but strange letters with it.
-----------
Oh my god!, i been watching this a few days ago and i completely forget it.
This code is from RSS.lua file on Shadow4. Is the same as the laaaaaarge function i wrote before. I was thinking of the Lua function to search and replace using regular expression, but then i thought... why reinvent the wheel:
| Code: |
function DecodeString(s)
s = string.gsub(s, "&#(%d+);",
function (d)
val = tonumber(d, 10)
if (val < 128) then
return string.char(val)
elseif (val < 2048) then
return string.char(192 + val / 64) .. string.char(128 + (val % 64))
elseif (val < 65536) then
return string.char(224 + val / 4096) .. string.char(128 + ((val / 64) % 64)) .. string.char(128 + (val % 64))
end
end)
end
|
This code take a numerical value &26143; for example and convert it to UTF-8.
I think all you need to do is:
| Code: |
sTime = DecodeString(os.date("%x %a"))
|
|
|
|
|
Last Edit: 2011/02/04 15:59 By Jorge_Luis.
|
|
|
Re:About Rainlendar_SetItemValue() 2 Years, 3 Months ago
|
|
|
Did you try to remove ":" from the string?yes, i did. it does not affect.
Code:
sTime = DecodeString(os.date("%x %a"))
function DecodeString(s)
s = string.gsub(s, "&#(%d+);", .........
i can not to get the "&#NNN;" of os.date("%x %a").
Anyway thank you Jorge_Luis.
Probably because I can not understand how it works, so I did not solve the problem.
I decided to not directly display <"今日情報:" .. os.date("%x %a")>,
but are independent display <"今日情報:"> and <os.date("%x %a")>
I hope someone can help solve.
|
|
|
|
I couldn't speak English! This skin released to Customize.org(Do you want it? Click Picture) Please contact me if interested: jhg5702@gmail.com

|
|
|