Giter Club home page Giter Club logo

punic's Introduction

Build Status Coverage Status Monthly Downloads Join the chat at https://gitter.im/punic/punic License

Punic - PHP Unicode CLDR Toolkit

Documentation

See punic.github.io for more info.

Contributing

We are always happy to get feedback or even pull requests. In order to keep the code consistent, please use the wonderful php-cs-fixer.

punic's People

Contributors

ahoogerheide avatar c960657 avatar danmichaelo avatar lukasreschke avatar mlocati avatar phil-davis avatar ragulka avatar remo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

punic's Issues

Country

Hello, I am using nextcloud, and taiwan isn't a country, could you please fix it to Taiwan(Province of China)?
Taiwan is a province of China.
And Wikipedia also shows this.
IMG_20191026_180531
67465569-fd234900-f677-11e9-8daf-4f2b4a4fd8cd

[Feature Request] Address formatting + Required information for country address

Many websites / online stores which have fields for address only show the required information for that particular country for filling in the address. In particular, this mostly concerns the state/provice/administrative area field which is not required by default in most countries.

I would suggest to add information in Punic for it to be able to tell the required fields for the country's address. This information can be fetched from Google's address data:
https://chromium-i18n.appspot.com/ssl-address

Definitions for the Google's data:
https://github.com/google/libaddressinput/wiki/AddressValidationMetadata

In the Google's data this can be found inside the require key for each country.

In addition, I think it would be great if Punic included the address formatting data, i.e. how to format the address string in each country. This can be also different depending on the country. That is also included in the Google's data inside the fmt key.

There is another project that already provides that but due to its external dependencies it may be difficult to install on some existing projects (you know which one):
https://github.com/commerceguys/addressing

I believe this would fit Punic's scope quite good as well.


There's no public licensing information for the data but the Java library itself is Apache License 2.0 and the specification page says "open-source address metadata". Here's also some discussion regarding the license (no official answer from Google but at least it can be expected to be under Apache License 2.0):
google/libaddressinput#155

Incorrect description of one year interval with locale "de"

Summary

Using package punic/punic:3.6.0 to describe an interval of one year with a width of long and the locale de leads to an incorrect result, which is immediately apparent to any German native speaker.

Reproduction

The following code prints the long description of an interval of one year in German:

$start = new \DateTimeImmutable();
$end = $start->add(new \DateInterval('P1Y'));
echo \Punic\Calendar::describeInterval($end, $start, 1, 'long', 'de'), PHP_EOL;

Expected Result

The code above should print the following correct output:

1 Jahr

Actual Result

The code above instead prints the following incorrect output:

1 Jahrs

Discussion

This package sources its locale data from https://github.com/punic/data, which in turn is sourced from https://github.com/unicode-org/cldr.

Executing the following command in punic/data's repository shows that it already contains the incorrect locale data:

$ php -r "echo (require 'docs/2/39/de/units.php')['long']['duration']['year']['one'], PHP_EOL;"
%1$s Jahrs

Inspecting unicode-org/cldr's repository shows that it contains the correct data: https://github.com/unicode-org/cldr/blob/651afecf9ccf1541a49306993e8210fa2209aa0b/common/main/de.xml#L8377 Therefore the error must be in punic/data's CLDR conversion. We can also see that unicode-org/cldr contains data for different grammatical cases (see also the table at https://de.wiktionary.org/wiki/Jahr). I would surmise that punic/data does not handle the grammatical cases correctly. It probably combines all grammatical cases, which makes the last one listed in the file win, which would be https://github.com/unicode-org/cldr/blob/651afecf9ccf1541a49306993e8210fa2209aa0b/common/main/de.xml#L8380, which is what is present in punic/data.

telephoneCodeData removed from CLDR 34

Follow up of #158 (comment)

I'd prefer copying the telephone data from CLDR 33 into future punic-data releases, rather than patching data from future CLDR releases back into to CLDR 33.

@c960657 I'd prefer to have an up-to-date reference data.
We simply need a list of territory code -> phone prefixes. Are you aware of such list that's reliable and up-to-date?

CLDR 44 support

At the end of October, version 44 of CLDR was released. Are there plans to add support for it?

Request for Measurement Data

Would it be possible include measurement data as well (found in /supplementalData/measurementData)?

It would be great as I am building a library for each country and all their settings.

Make compatible with HHVM

@bantu FYI – this library is used by ownCloud as well, the test suite is failing on HHVM with:

There was 1 failure:
1) CalendarTest::testFormat
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-GMT-1:02
+Fiji Standard Time

Thought not sure how relevant a test case containing Fiji Standard Time for us is…

nl locale returns array() for getTimezoneNameNoLocationSpecific

It seems the nl locale currently returns an empty array instead of an empty string when any getTimezoneNameNoLocationSpecific has no value.

$tz = new \DateTimeZone('Asia/Kathmandu');
$locale = 'nl';
var_dump(\Punic\Calendar::getTimezoneNameNoLocationSpecific($tz, 'short', '', $locale));

I have seen no other locale behave this way. And it doesn't adhere to the method signature.

PHPUnit scripts to test performance

So far I never cared much about performance as it was never a requirement for me, but there's definitely quite some potential.

  1. Do we want to use a library to cache certain things across multiple requests? A static array improves things a lot, but only for a single request. Using something like https://github.com/tedious/Stash could improve things even more in real life situations.
  2. What do you think about adding some PHPUnit scripts to test performance? I currently run each test function several times per call, seems to give me a pretty good indication. Only problem I currently have is the slightly weird test where we fetch the whole JSON file https://github.com/punic/punic/blob/master/tests/Plural/PluralTest.php#L25-L41 . I've vote to remove that with a data provider based test script. Also makes it nicer to test things as it runs much quicker.

Feature Request : Currency Formatter

Hey,

I love what you did with this library, however it is missing a currency formatter that takes in the amount and the currency and prints it out nicely,

This feature would be pretty useful, I tried looking everywhere in the API docs and couldn't find any but alot of the Node libraries that do the same thing (from CLDR) have a function like that.

Comparer.php Fails with special characters

Having issues when comparing special characters...

// file ./concrete/vendor/punic/punic/code/Comparer.php
   // .....
    public function compare($a, $b)
       // .....
       // failing when comparing "Latvia" and "St. Barthélemy"
       $result = $this->caseSensitive ? strnatcmp($a, $b) : strnatcasecmp($a, $b)
       // .....

Punic ignores Draft Status

Each piece of CLDR data comes with a draft status. See: http://cldr.unicode.org/index/process

approved (default if not specified)
contributed
provisional
unconfirmed

Punic is currently reading all four.

IMHO, provisional and unconfirmed data should be ignored by default. Possibly, an additional parameter in Punic API could be added, to explicitly allow use of provisional or unconfirmed data.

Inversion of control

This is a question.

Is there a way, out of the box, to use a DI/IoC type approach with this library. I see most of the singleton methods take a locale:

Calendar::getMonthName($dt, 'wide', 'it');

And if you want to use these functions everywhere in the application without constantly setting the locale, you can set the locale with the Data singleton:

Data::setDefaultLocale();
Calendar::getMonthName($dt, 'wide');

Does this mean that the locale is globally set everywhere? so you couldn't for example inject an environment to one set of classes with one default locale and another environment to another? For example something like:

$firstPunic = new Punic();
$firstPunic->setDefaultLocale('en');

$secondPunic = new Punic();
$secondPunic->setDefaultLocale('it');

$usesFirst = new UsesFirstEnvironment($firstPunic);
$usesSecond = new UsesSecondEnvironment($secondPunic);


final class UsesFirstEnvironment
{
    private $punic;
    
    public function __construct(Punic $punic)
    {
        $this->punic;
    }

    public function aMethod()
    {
        $this->punic->calendar()->getMonthName($dt, 'wide');
    }
}

final class UsesSecondEnvironment
{
    private $punic;
    
    public function __construct(Punic $punic)
    {
        $this->punic;
    }

    public function aMethod()
    {
        $this->punic->calendar()->getMonthName($dt, 'wide');
    }
}

If something a long these lines is not possible, I may have a PR implementing something like this at some stage (because my application can't work if I have to set globals on a singleton). Would you be interested in that PR?

Integrate Punic\Number::format in Punic\Unit::format

Punic\Unit::format formats a number associated to a unit.
For instance, with \Punic\Unit::format(2, 'millisecond', 'long', 'en') we have 2 milliseconds.
But we should also format the number.
Currently we have that \Punic\Unit::format(2000, 'millisecond', 'long', 'en') returns 2000 milliseconds, whereas we should obtain 2,000 milliseconds.
Problem: how to pass the wanted number of decimals (ie the $precision argument) to \Punic\Number::format()?
What about integrating it in the $width parameter of \Punic\Unit::format?
So, for instance:

  • \Punic\Unit::format(2000, 'millisecond', 'long', 'en') => 2,000 milliseconds
  • \Punic\Unit::format(2000, 'millisecond', 'long,2', 'en') => 2,000.00 milliseconds

subdivisionContainer uses deprecated China code

  • Punic Version 3.2.0

In the auto-generated files, subdivisionContainment.php uses the deprecated code for China subdivisions such as chah while the data file uses the new code ch34. This happens for all subdivision that has a new numeric code.

This issue raise the following error when using Territory::getList('s'):

Undefined index: cnah

Korean localePattern missing a space

I've just run into an issue with the localePattern for Korean. On closer inspection I notice this is not consistent with other languages, 'punic/code/data/ko/localeDisplayNames.json'

localePattern":"%1$s(%2$s)

All other languages use

localePattern":"%1$s (%2$s)

Request for Supplemental Data (WeekData, TerritoryCodes, TerritoryContainment)

Currently I retrieve the following myself parsing the /common/supplemental/supplementalData.xml file, however would appreciate if you could include these into Punic:

From /supplementalData/weekData:

  • weekendStart
  • weekendEnd

From /supplementalData/codeMappings/territoryCodes:

  • numeric
  • alpha3

/supplementalData/territoryContainment/group, as I need these to identify if a country is part of the EU community.

Thanks in advance!

Use of NumberFormatter/IntlDateFormatter

Hi,

Thanks for the great library! Just a quick question: any reason why you have implemented some number and date formatting functions whereas PHP's intl extension has built in classes (NumberFormatter/IntlDateFormatter), which are based on the same ICU/CLDR components?

Thanks! Sacha

punic-3.1.0/bin/build.sh missing, can't build additional language data.

Expected: Can build more language data.
Actual: Build script missing, can't build more language data.

punic-3.1.0/bin/build.sh build script is missing, and so "To keep the size of the package at a reasonable level, only data for a limited set of languages (about 40, defined here) is included by default. If you need more, you can build them yourself using the bundled build script." is incorrect in the documentation, as no actual build script is provided.

Supporting more languages

Specifically I would like to see support for nn. It would also be nice if the readme could mention or link to a list of supported languages, and describe the process for adding more. Let me know if I can help with something.

More default locales in releases

Hey,

I know I can build with more locales, but it is a pain to maintain a fork for an open source project just to have one or two more locales in the default list.

May I suggest that you add at least the top 20 countries with most internet users?
http://www.internetworldstats.com/top20.htm

This makes more sense. Currently, you have 40 locales in the package and to have these 20 countries on the list you need to add less than 5 more locales.

I also suggest that you check out the top 10 languages used on the web:
http://www.internetworldstats.com/stats7.htm

For example, you are clearly missing the Malaysia.

Ultimately, PHP is a scripting language used mostly used in web, so there should be a logical reason for choosing the locales to bundle as default with this library.

All being said, I used your library in the last couple of days and I should say, well done and thanks for developing such a life-saving piece of code. This is actually the best library I could find that do not download or cache CLDR information while running and don't need curl, allow_url_fopen or similar functions.

Human readable dates?

Hi
Thanks very much for creating this. I am using in a current project and am trying to format my dates:

 Calendar::describeInterval($time, $now, 1, 'long');

This is working and shows something like this: 4 months

I wanted this to be able to show if it is in the past or future: 4 months ago in 3 days etc.

I can see in the data that this looks ready to use but can't find in the documentation on how to format like this? Any advice?

Thanks,

Arabic language name in Finnish fails

Hello,

I have encountered an odd issue which I can't fully explain.

echo \Punic\Language::getName('ar','fi');

I got:

Notice:  Trying to access array offset on value of type null in /home/customer/www/common/composer/vendor/punic/punic/src/Data.php on line 692

Fatal error:  Uncaught Punic\Exception\InvalidLocale: A valid locale should be a string, NULL received in /home/customer/www/common/composer/vendor/punic/punic/src/Data.php:682
Stack trace:
#0 /home/customer/www/common/composer/vendor/punic/punic/src/Data.php(719): Punic\Data::getLocaleAlternatives(NULL, false)
#1 /home/customer/www/common/composer/vendor/punic/punic/src/Data.php(654): Punic\Data::getLocaleAlternatives('fi')
#2 /home/customer/www/common/composer/vendor/punic/punic/src/Data.php(261): Punic\Data::getLocaleFolder('fi')
#3 /home/customer/www/common/composer/vendor/punic/punic/src/Language.php(75): Punic\Data::get('languages', 'fi')
#4 /home/customer/www/common/web/classes/Common/LanguageStrings.php(992): Punic\Language::getName('ar', 'fi')
#5 /home/customer/www/common/web/classes/Common/LanguageStrings.php(899): Common\LanguageStrings->updateLanguageStringsLanguage()
#6 /home/customer/www/dev.webcal.guru/classes/WebCalGuru/Administration.php(2312): Common\LanguageStrings->updateLanguageStrings()
#7 /home/custo in /home/customer/www/common/composer/vendor/punic/punic/src/Data.php on line 682

The issue seemed to be in Data.php, row 536

$chunks = explode('-', str_replace('_', '-', strtolower($locale)));

The output of strtolower($locale) is fi-latn-fI (notice capital I in the end). I tested with every way I could, the strtolower('I') always gave the same upper case I. I've tried everything possible, and it simply does not give lower case i.

When I changed strtolower to mb_strtolower, it started working again.

I cannot explain this. Is it just me, or is there some UTF8 sequence involved? Perhaps in a data file, under Finland territory, the ending I is some UTF8 character, which mb_strtolower recognises as I, but strtolower does not?

Request for PostalCode Data

Would it be possible to get the Postalcode data from postalCodeData.xml? I am interested also getting the regular expressions of the postcodes.

Thanks! Sacha

Request for additional Supplemental Data information

Hi,

It would be great if also the supplemental data could be made available. In particular I am interested in:

  • Region/Currency (Which currency is used by what territory during what period).
  • TerritoryInfo (Population, GDP, etc.)

Thanks! Sacha

Norwegian Bokmål vs. Nynorsk

We currently support nn as the only Norwegian language:
https://github.com/punic/punic/blob/master/bin/build.php#L122

I have some doubts about that, because from what I can see Bokmål is spoken by more people:
A 2005 poll indicates that 86.3% use primarily Bokmål as their daily written language, 5.5% use both Bokmål and Nynorsk, and 7.5% use primarily Nynorsk.
https://en.wikipedia.org/wiki/Norwegian_language

I don't know much about the languages there, but it seems to be that we should add nb or replace nn with nb. Is there anyone who knows more about that?

Comparer exception if 'intl' not installed but using the symfony\collator.

If I try to create a new Comparer with a locale that is not 'en' and I do not have the 'intl' PHP extension installed but I do have the Symfony\Component\Intl\Collator\Collator loaded, I get an exception thrown when it could be handled gracefully.

An edge case that can be corrected externally, closing the issue, sorry!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.