Comments (13)
That's great. No problem, I can wait.
from gettext.
Done. See https://github.com/mlocati/cldr-to-gettext-plural-rules/
from gettext.
Nice!
I think this data should be saved in an external php file, so it can be re-generated in any time without modify the Locales class. What do you think about implementing something like this?:
php convert.php phparray locales-data.php
So, in Locales class, we can create a method to retrieve this information:
public static function getData()
{
if (!isset(self::$data)) {
self::$data = include __DIR__.'/locales-data.php';
}
return self::$data;
}
from gettext.
Nice idea. Done 😉
from gettext.
Ok, I've changed the Locales class to work with the new source. There are some changes, for example in the russian language that now has 4 plurals instead 3, I hope this is right (I have no idea).
I don't know whether the territories data is useful, but I've keept it anyway.
from gettext.
The russian language that now has 4 plurals instead 3, I hope this is right (I have no idea)
Previously we had 3 plurals with this formula:
(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)
But the CLDR data says this:
"ru": {
"pluralRule-count-one": "v = 0 and i % 10 = 1 and i % 100 != 11 @integer 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, …",
"pluralRule-count-few": "v = 0 and i % 10 = 2..4 and i % 100 != 12..14 @integer 2~4, 22~24, 32~34, 42~44, 52~54, 62, 102, 1002, …",
"pluralRule-count-many": "v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14 @integer 0, 5~19, 100, 1000, 10000, 100000, 1000000, …",
"pluralRule-count-other": " @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
},
As you can see, there should be 4 plurals.
And the new formula is
(n % 10 == 1 && n % 100 != 11) ? 0
:
((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1
:
((n % 10 == 0 || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 11 && n % 100 <= 14) ?
2
:
3
))
Which seems congruent with the CLDR data (for gettext we have that n == i
and v == 0
)
BUT the fourth case never occurs for integers... So, yes: it seems there's still some optimizations to be done...
from gettext.
There are 4 cases that I have to investigate.
You have eagle eyes ;) Thanks!
from gettext.
@oscarotero Ok, I added a procedure that removes the superfluous cases; the languages cleaned have been the 4 problematic ones: be- Belarusian,
pl- Polish,
ru- Russian and
uk` - Ukrainian.
from gettext.
Just a side note: Daiki Ueno (head developer of the gettext tools) seems interested in my cldr-to-gettext-plural-rules 😉
from gettext.
That's fantastic!!
I've pushed some changes with the new data exported by your tool and everything works fine.
You have eagle eyes ;) Thanks!
The phpunit test has eagle eyes 👓
from gettext.
@oscarotero Just a notice: https://packagist.org/packages/gettext/languages
from gettext.
Ok.
Do you think it's better to include this package as a dependency and generate the data using the composer post-install event?
from gettext.
If you include my package, you can also use the Language class without using pre-generated php code...
from gettext.
Related Issues (20)
- Cannot install version 5 on PHP 8 HOT 1
- Fatal: strlen() expects parameter 1 to be string MoGenerator.php HOT 1
- Update Documentation HOT 1
- Feature Request: WordPress gettext functions support for scanner HOT 2
- testMoGenerator fails HOT 2
- Why PHP >= 7.2 for Gettext v5? HOT 1
- How to load multiple *.mo files (general and for specific textdomain) HOT 3
- Plural parsing for MO files appears to ignore Plural-Forms HOT 2
- Gettext doesn`t extract template literals from JS HOT 1
- PHP 8.1 compatibility: warnings about JsonSerializable compatibility
- Make use of msgctxt HOT 1
- translations findById HOT 2
- Handling of defective .po files HOT 4
- PHP functions prefixed with a slash are being ignored HOT 3
- add a ?? to string reader for php8.1 in /src/Utils/StringReader.php HOT 2
- what is the equivilent of v4 Gettext->register() in v5? HOT 5
- [question] How to store arbitrary key-value payload in Translation objects, now that it can no longer be faked using references? HOT 1
- Scanner for WordPress (provided repo link) HOT 1
- [Question] Simplest way to promote items in a Translations object to a subclass? HOT 1
- How do I configure to scan files for my own custom funtions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gettext.