Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Internationalization (v4)
 Give it a try: FlangSP (Singular/Plural)
 Forum Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 3

Deleted
deleted

4116 Posts

Posted - 09 May 2002 :  14:44:35  Show Profile
This one was missing. We didn't have a solution for singular/plural cases.

This is the code (may need some more optimization). Please do some simple coding and try it and see if it fits your language...


' Function fLangSP(s: string, paramlist)
' Used for sentences which are mixed with variables from code AND has singular-plural cases. Parameters are parsed and inserted
' into the sentence. The places of insertion are defined in the value of the string as %sN% where N
' (1,2,3...) indicates the variable. The singular/plural words are indicated by [%N]singular|plural[/%N] where N is the
' numeric parameter to be checked for using singular or plural case.
' INPUT
' ==== s: String of language variable name ==== changed for IIS4 compatibility
' s: String (language variable)
' paramlist: String, Separeted list of variable values. The format is : "param1|param2|..."
' where | is used as separetor. ParamN is used to replace variable %sN%.
' EXAMPLE
' ==== response.write fLangSP("strLangDefault00060", intNoOfRecords & "|" & intMaxRecords) ==== changed for IIS4 compatibility
' response.write fLangSP(strLangDefault00060, intNoOfRecords & "|" & intMaxRecords)
'
function fLangSP(s, paramlist)
DIM s1, s2, arrParam, sp, N, i, pos1, pos2, pos3, strErr
' s=eval(s) ' commented out for IIS 4 compatibility, all related function calls changed
s1 = s
arrParam = split(paramlist, "|")
N=ubound(arrParam)
for i=0 to N
s1=replace(s1,"%s" & i+1 & "%", arrParam(i))
pos1 = 1
strErr = ""
Do While pos1 > 0
pos1 = InStr(1, s1, "[%" & i+1 & "]", 0)
if pos1 > 0 then ' starting tag found, so search for closing tag
pos2 = InStr(pos1, s1, "[/%" & i+1 & "]", 0)
if pos2 > 0 then ' closing tag found, so extract singular|plural string and search for "|" separator
s2=mid(s1, pos1+4, (pos2-1)-(pos1+4)+1) ' get the content
pos3 = InStr(1, s2, "|", 0)
if pos3 > 0 then 'do the replacement
if arrParam(i) = 1 then ' singular case
s1 = left(s1, pos1-1) & left(s2,pos3-1) & mid(s1, pos2+5)
else ' plural case
s1 = left(s1, pos1-1) & mid(s2,pos3+1) & mid(s1, pos2+5)
end if
else ' error: no separator
strErr = strErr & " Error: No Separator in " & mid(s1,pos1,pos2+4-pos1+1)
end if
else ' error: no closing tag
strErr = strErr & " Error: No Closing Tag for " & mid(s1,pos1,4)
end if
end if
loop
next
if blnLangDebug then
fLangSP = "*" & s1
else
fLangSP = s1
end if
end function


And here is an example string:

strLangTest = "There [%1]is|are[/%1] %s1% [%1]topic|topics[/%1] in %s2% [%2]forum|forums[/%2]."


This is how you call it:

response.write fLangSP(strLangTest, "2|1")



Think Pink
==> Start Internationalization Here<

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 09 May 2002 :  16:17:05  Show Profile  Send ruirib a Yahoo! Message
???

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
<
Go to Top of Page

RichardKinser
Snitz Forums Admin

USA
16655 Posts

Posted - 09 May 2002 :  16:24:10  Show Profile
fixed... <
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 09 May 2002 :  16:42:17  Show Profile
quote:

fixed...



What was it ?


Think Pink
==> Start Internationalization Here<
Go to Top of Page

RichardKinser
Snitz Forums Admin

USA
16655 Posts

Posted - 09 May 2002 :  16:49:43  Show Profile
just edit the post and look where I inserted this: (it's in 2 places)

[b][/b]<
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 09 May 2002 :  17:00:34  Show Profile
quote:

just edit the post and look where I inserted this: (it's in 2 places)

[b][/b]



Ooo thanks. I actually did look in edit mode but could not see anything... I was deeply surfing after some people and didn't look at the result output. In any post where there is a [ and/or ], I had to preview...

(yes I did for this also :)


Think Pink
==> Start Internationalization Here<
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 11 May 2002 :  00:06:56  Show Profile
Bump!

Think Pink
==> Start Internationalization Here<
Go to Top of Page

LC
New Member

Brazil
70 Posts

Posted - 11 May 2002 :  14:35:12  Show Profile
Where should I put it?

<
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 11 May 2002 :  14:52:12  Show Profile
quote:

Where should I put it?



Create a new file (say test.asp), put the function, the variable and the function call (in this order) in that file between "<% %>" tags. Then run it from your browser.

Next, change the variable strLangTest to a sentence in your language (must not be the same, try more complicated cases) and test again, and report here if it works OK in your case.


Think Pink
==> Start Internationalization Here<
Go to Top of Page

Survivor
Starting Member

Russia
10 Posts

Posted - 18 May 2002 :  03:40:10  Show Profile
English version works fine, but in russian not such well... Russian language has many forms of words in both singular and plural that must be dealed separately:

strLangTest = "There [%1]is|are[/%1] %s1% [%1]topic|topics[/%1] in %s2% [%2]forum|forums[/%2]." - original
strLangTest = "Èìååòñÿ %s1% [%1]òåìà|òåì[/%1] â %s2% [%2]ôîðóìå|ôîðóìàõ[/%2]." - in russian


for "topic/topics" in russian

When number ended with 1 (example: 1, 21, 51, etc) it must be writed as "òåìà" (in russian)
When number ended with 2 to 4 (example: 2, 23, 54, etc) it must be writed as "òåìû"
When number ended with 5 to 10 (example: 0, 5, 27, 60, etc) it must be writed as "òåì"


for "forum/forums"

When number ended with 1 (example: 1, 21, 51, etc) it must be writed as "ôîðóì" (in russian)
When number ended with 2 to 4 (example: 2, 23, 54, etc) it must be writed as "ôîðóìà"
When number ended with 5 to 10 and from 11 to 20 (example: 0, 5, 27, 60, etc) it must be writed as "ôîðóìîâ"

So... your code doesn't work with russian ...

<
Go to Top of Page

inworg
Junior Member

Italy
153 Posts

Posted - 18 May 2002 :  05:41:14  Show Profile  Visit inworg's Homepage
Tested using italian lang.
Seems all ok!

Russian lang seems a big problem instead....

The only way out seems to use LCID to handle lang "exceptions"....



....added after some minutes....

quote:
When number ended with 1 (example: 1, 21, 51, etc) it must be writed as "ôîðóì" (in russian)
When number ended with 2 to 4 (example: 2, 23, 54, etc) it must be writed as "ôîðóìà"
When number ended with 5 to 10 and from 11 to 20 (example: 0, 5, 27, 60, etc) it must be writed as "ôîðóìîâ"



If russian is the only lang (I hope!) that has this kind of problem, maybe not difficult to re-code the function to work great with russian lang too.....



Edited by - inworg on 18 May 2002 05:49:10<
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 18 May 2002 :  06:32:52  Show Profile
Thank you for the feedback. I also think that this function can have some select case part for processing of different locales.

Think Pink
==> Start Internationalization Here<
Go to Top of Page

Romee
Junior Member

Netherlands
180 Posts

Posted - 22 May 2002 :  12:51:13  Show Profile
No problem for Frisian.
See:
http://www.forumpagina.com/fries/test.asp
Romée

<
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 22 May 2002 :  13:06:13  Show Profile  Send ruirib a Yahoo! Message
How would this function handle a situation like the one in let's say, Active Users:

If I want to show the time since a user has logged in I would write "1 minute" but for any other amounts I wanted to show "x minutes" where x may assume any value <> 1.
Doesn't the funcion force you to have all the possible values listed, separated by '|'? If so (and it seems so) it is not as useful as it could be, right?



-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
<
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 22 May 2002 :  13:39:12  Show Profile
[edit]Corrected some typing mistakes which could cause problems otherwise, marked them with red.[/edit]

quote:

If I want to show the time since a user has logged in I would write "1 minute" but for any other amounts I wanted to show "x minutes" where x may assume any value <> 1.
Doesn't the funcion force you to have all the possible values listed, separated by '|'? If so (and it seems so) it is not as useful as it could be, right?



I think I understand this. The first version of the function given above is valid for languages which have "regular" singular/plurals, and those with no singular/plurals:


Singular : =1
Plural : <> 1


It also deals with cases like in Turkish (below is the Turkish translation for "1 child is coming" and "10 children are coming")


Singular : 1 çocuk geliyor
Plural : 10 çocuk geliyorlar


As you see, the word "çocuk=child" does not get the plural, because "10 çocuk" is considered as plural, and double plural is forbidden in Turkish. But the verb has "lar" at the end to make it plural.

So I can use the above function like this


strLangTest = "%s1% [%1]çocuk|çocuk[/%1] [%1]geliyor|geliyorlar[/%1]."


and call it like


fLangSP(strLangTest, intNoOfChildren)


Coming to your question... No it does not need multiple values in English and in most languages. You can use:


strLangTest = "%s1% [%1]minute|minutes[/%1]"


and call it like


fLangSP(strLangTest, intNoOfMinutes)


So the possible outputs are:


"1 minute"


and


"2 minutes" (you can have any number instead of "2" except "1" to get this)


While thinking I have these questions:


  • how do you handle 0 (zero) => "there are 0 topics"

  • how do you handle negative numbers (zero) => "there are -5 topics"

  • how do you handle decimal numbers => "You are online for 3.57 minutes"



It does not handle cases like survivor told us above thou, i.e. different ranges for different words. I'm working on a new more "customizable" version to also handle these cases. I plan to work together with survivor to get it right.


Think Pink
==> Start Internationalization Here

Edited by - bozden on 22 May 2002 17:25:14<
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 22 May 2002 :  16:57:46  Show Profile  Send ruirib a Yahoo! Message
I see Bozden. I'll have a better look at this and get back to ya then.
Thanks.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
<
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Next Page
 Forum Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000 Version 3.4.07