PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: Light on 15 December, 2006, 14:20:54

Title: string.lower() problem
Post by: Light on 15 December, 2006, 14:20:54
Hi to all, all word replace scripts don't work with russian, becaue function string.lower don't understand it.. how may fix this problem?
Title: Re: string.lower() problem
Post by: Madman on 15 December, 2006, 16:53:27
Use a table...
before string.lower the text, do a for loop and gsub the letters.
If you can't figuer it out, i got an example code
Title: Re: string.lower() problem
Post by: Herodes on 15 December, 2006, 17:36:34
There must be something to do with os.setlocale :
Quote from: Lua5.1Manual
os.setlocale (locale [, category])

Sets the current locale of the program. locale is a string specifying a locale; category is an optional string describing which category to change: "all", "collate", "ctype", "monetary", "numeric", or "time"; the default category is "all". The function returns the name of the new locale, or nil if the request cannot be honored.

When called with nil as the first argument, this function only returns the name of the current locale for the given category.

I believe yours may work like:
os.setlocale('ru_RU')
Title: Re: string.lower() problem
Post by: speedX on 15 December, 2006, 20:04:47
oh man, those hyper-difficult codes make me feel sick :(
Is there any site or module wich contains all the codes of ptokax??
Title: Re: string.lower() problem
Post by: Herodes on 16 December, 2006, 10:39:54
Quote from: speedX on 15 December, 2006, 20:04:47
oh man, those hyper-difficult codes make me feel sick :(
Is there any site or module wich contains all the codes of ptokax??
what codes ?
do you mean 'ru_RU', 'el_GR' ?
check this out :) (http://search.cpan.org/~drolsky/DateTime-Locale-0.32/lib/DateTime/LocaleCatalog.pm)
Title: Re: string.lower() problem
Post by: Light on 16 December, 2006, 21:52:11
os.setlocale('ru_RU') - no effect..
Madman, please give me example
Title: Re: string.lower() problem
Post by: Herodes on 18 December, 2006, 08:50:05
Quote from: Light on 16 December, 2006, 21:52:11
os.setlocale('ru_RU') - no effect..
Madman, please give me example
Where did you use it in the script? I suppose you should use it in Main().


function Main()
os.setlocale("ru_RU")
assert(os.setlocale() == "ru_RU", "The locale wasn't set")
end
Title: Re: string.lower() problem
Post by: bastya_elvtars on 18 December, 2006, 11:47:42
IIRC you can directly assert os.setlocale("ru_RU"), since it returns nil on failure.
Title: Re: string.lower() problem
Post by: Light on 18 December, 2006, 14:16:09
Yes, i use it in main(). it returns nil..
This problem appers in lua 5.1 version, in older versions string functions processing normaly
Title: Re: string.lower() problem
Post by: Madman on 21 December, 2006, 03:40:20

BadLetters = {
["?"] = "?",
["?"] = "?",
["?"] = "?",
}

function ChatArrival(curUser,data)
local data = string.sub(data,1,-2)
local s,e,text = string.find(data,"%b<>(.+)")
for Upper,Lower in pairs(BadLetters) do
if string.find(text,Upper) then
text = string.gsub(text,Upper,Lower)
end
end
SendToAll(curUser.sName,string.lower(text)) return 1
end


Hopes it helps...