Singular & plural form using the zo_strformat() function
Lua Code:
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" |
You can also do
Code:
pattern = "I have sold <<1[no items/a single item/$d items]>>." 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" |
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:
We can modify pattern even further using the $d variable: Lua Code:
Also we can leave empty any of the forms, so there will be no return value. Good example is time format: Lua Code:
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" |
Thanks for this information. I saw those strings in the zgoo display but couldn't figure out how they are used.
|
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) |
Beautiful, Garkin. :)
|
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:
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. |
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" |
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. |
Quote:
|
Quote:
"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 :mad: Update: I just tried the stupid programmer approach and did: <<!A:1>> (not A) - and it actually worked and removed the definite article :D :banana: |
Quote:
Lua Code:
returns "first" if text == "test^f" returns "second" if text == "test^n" returns "second" if text == "test^p" returns "second" Lua Code:
returns "first" if text == "test^f" returns "second" if text == "test^n" returns "first" if text == "test^p" returns "third" Lua Code:
returns "first" if text == "test^f" returns "second" if text == "test^n" returns "third" if text == "test^p" returns "fourth" |
Quote:
|
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] |
All times are GMT -6. The time now is 07:14 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI