Thread Tools Display Modes
05/09/14, 05:13 AM   #1
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Singular & plural form using the zo_strformat() function

Lua Code:
  1. pattern = "I have sold <<1>> <<1[items/item/items]>>."
  2.  
  3. msg = zo_strformat(pattern, num)

If num = 0
<<1>> is replaced by num and <<1[items/item/items]>> returns first from
msg = "I have sold 0 items"

if num = 1
<<1>> is replaced by num and <<1[items/item/items]>> returns second from
msg = "I have sold 1 item"

if num > 1
<<1>> is replaced by num (eg 5) and <<1[items/item/items]>> returns third from
msg = "I have sold 5 items"
  Reply With Quote
05/09/14, 05:57 AM   #2
slowglass
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 8
You can also do
Code:
pattern = "I have sold <<1[no items/a single item/$d items]>>."
msg = zo_strformat(pattern, num)
If num = 0
msg = "I have sold no items"

if num = 1
msg = "I have sold a single item"

if num > 1 (ie 5 in this case)
msg = "I have sold 5 items"
  Reply With Quote
05/09/14, 06:05 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
When we define just 2 forms in pattern, it means that first form is for num = 1 and second form for anything else. So, this pattern will have the same output as in example above:

Lua Code:
  1. pattern = "I have sold <<1>> <<1[item/items]>>."


We can modify pattern even further using the $d variable:
Lua Code:
  1. pattern = "I have sold <<1[$d item/$d items]>>"
$d will get replaced with actual value of argument, so output will be the same as in both examples above.


Also we can leave empty any of the forms, so there will be no return value. Good example is time format:
Lua Code:
  1. pattern = "Remaining time: 1[/1 minute and /$d minutes and ]>><<2[1 second/$d seconds]>>"
  2.  
  3. msg = zo_strformat(pattern, min, sec)

As we do not have defined form for zero value for minutes, output will be:
if min = 0, sec = 1
msg = "Remaining time: 1 second"

if min = 0, sec = 5
msg = "Remaining time: 5 seconds"

if min = 5, sec = 0
msg = "Remaining time: 5 minutes and 0 seconds"

Last edited by Garkin : 05/10/14 at 08:02 PM.
  Reply With Quote
05/09/14, 06:14 AM   #4
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Thanks for this information. I saw those strings in the zgoo display but couldn't figure out how they are used.
  Reply With Quote
05/09/14, 08:00 AM   #5
CrazyDutchGuy
 
CrazyDutchGuy's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 89
Garkin pointed me helpfully to this information at my addon.

I tried figuring out how it would work correclty with the plurality forms of item links and i couldn't figure it out how it works properly.

For example

the m: would define the plural form of the item

Code:
zo_strformat("<<1>> <<2>> <<m:3>>", player, quantity, itemlink)
the question i couldn't figure out is how to define the plural form of the item based on the quantity. The strings in zgoo display just generally use the single form.
  Reply With Quote
05/09/14, 09:09 AM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Beautiful, Garkin.
  Reply With Quote
05/09/14, 09:11 AM   #7
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Reading the thread title I had hoped to get an answer for a slightly different problems.


Some words/strings are localized in singular and some in plural form.

How can you modify the string depending on the form?

Basically I need something like:

Lua Code:
  1. if localizedword == singular then
  2. auxVerb = "xyz"
  3. elseif localizedword == plural then
  4. auxVerb == "abc"
  5. end
  6. string.format("bla bla %s %s", auxVerb , localizedword)

Yes, that's the way I can do it, I was wondering though if there is a smart zo_strformat solution. There are fragments like <<1[/m/f]>> in EsoStrings, which looks like there is a way, but no idea how they need to be used and combined properly.

Basically something similar to the solution here, just without a number involved.
  Reply With Quote
05/09/14, 10:42 AM   #8
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
There are also other control characters, but without documentation is hard to say if I got them all and if it is correct:

a: - adds indefinite article in correct form ("a/an") if string is not name (does not contain ^M,^F,^N). If used with m (<<ma:1>>) it will add "some".
A: - adds definite article if string is not name (does not contain ^M,^F,^N)
c: - converts first character to lower case
C: - converts first character to upper case, used to display names
d: - demonstrative pronoun, adds "this" if string is not name (does not contain ^M,^F,^N)
D: - returns demonstrative pronoun
g: - adds " of a", if string is name it will add to the end "'s" for singular, "'" for plural
G: - adds " of the" if string is name it will add to the end "'s" for singular, nothing for plural
i: - changes number to index (1st,2nd,3rd,....100th)
I: - the same as above?
l: - adds "at the ", used with locations
L: - adds "to the ", used with locations
m: - multiplication, displays singular or plural accoding to the second argument. If you have number on any other position, this will not work.
n: - number to text (one, two, three, ..., twelve). Does not work for numbers higher then 12.
N: - same as above, just first letter is capital (One,Two,...)
o: - possessive pronoun (subject). Returns his, her, its according to the ^m, ^f, ^n on the end of string
O: - possessive pronoun (object). Returns his, hers, its.
p: - personal pronoun (subject). Returns he, she, it accoding to the ^m, ^f, ^n on the end of string
P: - personal pronoun (object). Returns him, her, it.
r: - reflexive pronoun. Returns himself, herself, itself accoding to the ^m, ^f, ^n on the end of string
R: - number to roman numerals.
t: - converts first letter to upper case in all words that have more than 1 character (used by default to format item links)
T: - converts first letter to upper case in all words (including single letter words)
x: - changes link to plain text (EDIT: as of Update 3 this doesn't work)
X: - raw format (probably, it does not remove ^ control chars from strings, links are unchanged.)
z: - converts text to lower case letters, works for special characters like ÁÉÄËÍÏ etc.
Z: - converts text to upper case letters, works for special characters like áäéëíï etc.

- control characters are used in form <<Z:1>> or <<1{Z}>>
- instead of <<2>><<m:1>> can be used simplified form <<2*1>>

Almost all control charactes can be used together, so:
zo_strformat("<<C:1>> <<2>> <<tm:3>>", "i have", 10, "blue colored item")
will return "I have 10 Blue Colored Items"

If you want to work with translations, there are a few control characters that you can add to the end of string:
^f - femine gender
^F - femine name
^m - masculine gender
^M - masculine name
^n - neuter gender
^N - neuter name
^p - plural
^P - plural name

Example:
zo_strformat("<<g:1>><<2>>", "Peter^M", "item")
returns "Peter's item"

Last edited by Garkin : 01/24/15 at 06:33 AM. Reason: Updated x:
  Reply With Quote
05/09/14, 11:17 AM   #9
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Another catch:

<<player{first item/second item}>>
returns first item when player character is male, second item if character is female.

<<1{first/second/third}>>
returns first if argument is masculine, second if femine and third if plural.
  Reply With Quote
05/09/14, 11:45 AM   #10
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Garkin View Post

<<1{first/second/third}>>
returns first if argument is masculine, second if femine and third if plural.
plural? Either neutral or some strings are broken. Using the POI "Tangle Rock" on this returns the third argument.
  Reply With Quote
05/09/14, 12:24 PM   #11
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Garkin View Post
A: - adds definite article if string is not name (does not contain ^M,^F,^N)
Hm.

"Magiergilde^fd" (Mages guild skill line name) together with <<1>> results already in a definite article added -> "die Magiergilde"

Trying to get rid of it


Update:

I just tried the stupid programmer approach and did:
<<!A:1>> (not A) - and it actually worked and removed the definite article

Last edited by Iyanga : 05/09/14 at 12:35 PM.
  Reply With Quote
05/10/14, 12:57 PM   #12
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Iyanga View Post
plural? Either neutral or some strings are broken. Using the POI "Tangle Rock" on this returns the third argument.
Lua Code:
  1. local fmt = <<1{first/second}>>
  2. msg = zo_strformat(fmt, text)
if text == "test^m"
returns "first"

if text == "test^f"
returns "second"

if text == "test^n"
returns "second"

if text == "test^p"
returns "second"

Lua Code:
  1. local fmt = <<1{first/second/third}>>
  2. msg = zo_strformat(fmt, text)
if text == "test^m"
returns "first"

if text == "test^f"
returns "second"

if text == "test^n"
returns "first"

if text == "test^p"
returns "third"

Lua Code:
  1. local fmt = <<1{first/second/third/fourth}>>
  2. msg = zo_strformat(fmt, text)
if text == "test^m"
returns "first"

if text == "test^f"
returns "second"

if text == "test^n"
returns "third"

if text == "test^p"
returns "fourth"
  Reply With Quote
05/10/14, 01:03 PM   #13
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Iyanga View Post
Hm.

"Magiergilde^fd" (Mages guild skill line name) together with <<1>> results already in a definite article added -> "die Magiergilde"

Trying to get rid of it


Update:

I just tried the stupid programmer approach and did:
<<!A:1>> (not A) - and it actually worked and removed the definite article
I was wondering what it means "<<!aC:1>>" in german EsoStrings...
  Reply With Quote
05/18/14, 11:38 AM   #14
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
And another note:

Using m with items is not worth the time, there is no way to get correct output for German.

There seems to be an algorithm if the string has no ^p version to turn a normal string into a plural string, i.e. to add the letter "e" or "n". But the algorithm fails very often.

The results for example:
"Backfett" -> "Backfette" [OK]
"Käse" -> "Käsee" [NOK]
  Reply With Quote

ESOUI » Developer Discussions » Tutorials & Other Helpful Info » Singular & plural form using the zo_strformat() function

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off