MichaelChirico / potools

Tools for working with translations in R
https://michaelchirico.github.io/potools/
58 stars 3 forks source link

Document how to handle plurals (for translators and developers) #228

Closed hadley closed 2 years ago

hadley commented 2 years ago

Seems like it would be useful to include this somewhere?

```R library(rvest) html <- read_html("https://l10n.gnome.org/teams/") teams <- html %>% html_nodes(".column_container li > a") %>% html_attr("href") urls <- paste0("https://l10n.gnome.org", teams) find_plural_form <- function(url) { print(url) url %>% read_html() %>% html_node("#content > div > p") %>% html_text() } forms <- sapply(urls, find_plural_form) names(forms) <- teams %>% gsub("^/teams/", "", .) %>% gsub("/$", "", .) split(names(forms), forms) ``` ``` $`Plural forms: nplurals=1; plural=0` [1] "hy" "zh_CN" "zh_trad" "dz" "ka" "id" "ja" "kk" [9] "km" "ky" "ko" "lo" "ms" "fa" "th" "tr" [17] "ug" "vi" $`Plural forms: nplurals=1; plural=0;` [1] "my" "bo" $`Plural forms: nplurals=2; plural= n==1 || n%10==1 ? 0 : 1` [1] "mk" $`Plural forms: nplurals=2; plural=(n != 1)` [1] "ab" "af" "sq" "an" "ast" "az" "eu" "bn" "brx" "bg" [11] "ca" "ckb" "nhn" "da" "nl" "eo" "et" "fi" "fy" "fur" [21] "gl" "de" "el" "gu" "ht" "ha" "he" "hi" "hu" "it" [31] "mjw" "ml" "mr" "es_MX" "mn" "ne" "nso" "no" "or" "os" [41] "ps" "pt" "pa" "es" "sw" "sv" "tg" "ta" "te" "tk" [51] "ur" "guc" $`Plural forms: nplurals=2; plural=(n != 1);` [1] "en_AU" "en_GB" "en_CA" "fo" "ts" $`Plural forms: nplurals=2; plural=(n !=1)` [1] "nds" $`Plural forms: nplurals=2; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : 1;` [1] "quz" $`Plural forms: nplurals=2; plural=(n % 100 != 1 && n % 100 != 21 && n % 100 != 31 && n % 100 != 41 && n % 100 != 51 && n % 100 != 61 && n % 100 != 71 && n % 100 != 81 && n % 100 != 91)` [1] "is" $`Plural forms: nplurals=2; plural=(n > 1)` [1] "ak" "am" "pt_BR" "fr" "ia" "mg" "mi" "oc" "wa" $`Plural forms: nplurals=2; plural=(n > 1);` [1] "ln" $`Plural forms: nplurals=2; plural=(n!= 1)` [1] "ku" $`Plural forms: nplurals=2; plural=(n!=1)` [1] "kn" $`Plural forms: nplurals=2; plural=n != 1` [1] "so" $`Plural forms: nplurals=2; plural=n != 1;` [1] "lg" $`Plural forms: nplurals=2; plural=n>1` [1] "kab" $`Plural forms: nplurals=2;plural=(n>1);` [1] "kg" $`Plural forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2)` [1] "lv" $`Plural forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2)` [1] "lt" $`Plural forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)` [1] "be" "bs" "hr" "ru" $`Plural forms: nplurals=3; plural=(n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);` [1] "ro" $`Plural forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)` [1] "pl" "szl" $`Plural forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2` [1] "cs" $`Plural forms: nplurals=3; plural=(n==1) ? 1 : (n>=2 && n<=4) ? 2 : 0` [1] "sk" $`Plural forms: nplurals=3; plural=n == 1 ? 0 : (n == 2 ? 1 : 2);` [1] "gv" $`Plural forms: nplurals=4; plural= (n==1) ? 0 : (n==2) ? 1 : (n != 8 && n != 11) ? 2 : 3` [1] "cy" $`Plural forms: nplurals=4; plural=(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 or n%100==4 ? 3 : 0) ` [1] "sl" $`Plural forms: nplurals=4; plural=(n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3;` [1] "gd" $`Plural forms: nplurals=4; plural=n==1 ? 3 : n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2` [1] "uk" $`Plural forms: nplurals=4; plural=n==1? 3 : n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2` [1] "sr" $`Plural forms: nplurals=5; plural=n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4` [1] "ga" $`Plural forms: nplurals=6; plural= n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;` [1] "ar" $`Plural forms: Unknown` [1] "as" "bal" "bem" "bn_IN" "br" "crh" "dv" "ff" [9] "gn" "io" "az_IR" "ks" "rw" "la" "li" "mai" [17] "ang" "en@shaw" "si" "tl" "tt" "uz" "xh" "yi" [25] "yo" "zu" ```
hadley commented 2 years ago

A bit more info about plural forms at https://www.gnu.org/software/gettext/manual/gettext.html#Translating-plural-forms

hadley commented 2 years ago

And more description at https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html#Plural-forms

MichaelChirico commented 2 years ago

There is this:

https://github.com/MichaelChirico/potools/blob/master/inst/extdata/language_metadata.csv

and

https://github.com/MichaelChirico/potools/blob/master/inst/extdata/plurals_metadata.csv

Could you elaborate what you'd want as input/output here?

hadley commented 2 years ago

I think what I want is a write up of how to handle plurals from the developer perspective (i.e. plurals in languages are more complicated than you might thinks), and the translator perspective (i.e. here the definition of the pluralisation system for your language, and how you need to order the translations).