New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

666: Add CLDR support #784

Open
wants to merge 28 commits into
from

Conversation

Projects
None yet
4 participants
@toolstack
Contributor

toolstack commented Jul 7, 2017

Resolves #666.

@toolstack

This comment has been minimized.

Show comment
Hide comment
@toolstack

toolstack Jul 7, 2017

Contributor

A couple of notes on the current state of this:

  • I have only added CLDR plurals support to the android format, the Apple strings format remains to be done.
  • The test cases haven't been updated to do importing of CLDR plurals yet and the export test case is a bit of a fudge ;)
  • There's probably a few more docblocks to be written.
Contributor

toolstack commented Jul 7, 2017

A couple of notes on the current state of this:

  • I have only added CLDR plurals support to the android format, the Apple strings format remains to be done.
  • The test cases haven't been updated to do importing of CLDR plurals yet and the export test case is a bit of a fudge ;)
  • There's probably a few more docblocks to be written.

@toolstack toolstack requested a review from ocean90 Jul 7, 2017

@yoavf

Really happy to see this PR. Left a few comments on a few very minor issues spotted while taking a quick look

Show outdated Hide outdated bin/locale-generator/locale-generator.php
/*
* Get the CLDR Data.
*
* By defualt it is read from the plurals.json file in the current directory, you can download

This comment has been minimized.

@yoavf

yoavf Jul 10, 2017

Member

typo defualt

@yoavf

yoavf Jul 10, 2017

Member

typo defualt

Show outdated Hide outdated bin/locale-generator/locale-generator.php
// Create a working locales object.
$locales = new GP_Locales;
// Run through the locales and see if we can find a mathcing CLDR locale.

This comment has been minimized.

@yoavf

yoavf Jul 10, 2017

Member

Typo in mathcing

@yoavf

yoavf Jul 10, 2017

Member

Typo in mathcing

Show outdated Hide outdated tests/phpunit/testcases/tests_formats/test_format_android.php
@@ -24,11 +27,22 @@ function test_export() {
$entries_for_export = array();
foreach( $this->entries as $sample ) {
list( $context, $original, $translation ) = $sample;
list( $context, $original, $translation, $comment ) = $sample;

This comment has been minimized.

@yoavf

yoavf Jul 10, 2017

Member

Is the addition of the comment intentional in this patch?

@yoavf

yoavf Jul 10, 2017

Member

Is the addition of the comment intentional in this patch?

This comment has been minimized.

@toolstack

toolstack Jul 10, 2017

Contributor

Yes, but only because it fixes an existing bug in the test case.

@toolstack

toolstack Jul 10, 2017

Contributor

Yes, but only because it fixes an existing bug in the test case.

@toolstack toolstack added this to the 3.0 milestone Jul 11, 2017

Show outdated Hide outdated gp-includes/template.php
*
* @return string HTML markup for a select element.
*/
function gp_plurals_dropdown( $name_and_id, $selected_plural_type = null, $attrs = array() ) {

This comment has been minimized.

@ocean90

ocean90 Oct 3, 2017

Member

Let's name this gp_plural_types_dropdown().

@ocean90

ocean90 Oct 3, 2017

Member

Let's name this gp_plural_types_dropdown().

This comment has been minimized.

@toolstack

toolstack Oct 3, 2017

Contributor

👍

@toolstack

toolstack Oct 3, 2017

Contributor

👍

Show outdated Hide outdated gp-templates/project-form.php
@@ -12,6 +12,9 @@
<dt><label for="project[description]"><?php _e( 'Description', 'glotpress' ); ?></label> <span class="ternary"><?php _e( 'can include HTML', 'glotpress' ); ?></span></dt>
<dd><textarea name="project[description]" rows="4" cols="40" id="project[description]"><?php echo esc_html( $project->description ); ?></textarea></dd>
<dt><label for="project[plurals_type]"><?php _e( 'Plurals Type', 'glotpress' ); ?></label></dt>
<dd><?php echo gp_plurals_dropdown( 'project[plurals_type]', $project->plurals_type, array() ); // WPCS: XSS ok. ?></dd>

This comment has been minimized.

@ocean90

ocean90 Oct 3, 2017

Member

gp_plurals_dropdown() should be added to customAutoEscapedFunctions in phpcs.xml.

@ocean90

ocean90 Oct 3, 2017

Member

gp_plurals_dropdown() should be added to customAutoEscapedFunctions in phpcs.xml.

This comment has been minimized.

@toolstack

toolstack Oct 3, 2017

Contributor

👍

@toolstack

toolstack Oct 3, 2017

Contributor

👍

Show outdated Hide outdated bin/locale-generator/locale-generator.php
} // End foreach().
// Add some space between locales for easier reading.
echo "\n"; // WPCS: XSS ok.

This comment has been minimized.

@ocean90

ocean90 Oct 3, 2017

Member

Can we ignore the variants part in this PR for now?

@ocean90

ocean90 Oct 3, 2017

Member

Can we ignore the variants part in this PR for now?

This comment has been minimized.

@toolstack

toolstack Oct 3, 2017

Contributor

Not easily without breaking one or both of the patches :)

They both do a lot of work on the locales file so separating them is hard.

@toolstack

toolstack Oct 3, 2017

Contributor

Not easily without breaking one or both of the patches :)

They both do a lot of work on the locales file so separating them is hard.

Show outdated Hide outdated bin/locale-generator/locale-generator.php
}
}
}
} // End foreach().

This comment has been minimized.

@ocean90

ocean90 Oct 3, 2017

Member

These are no longer required and can be removed.

@ocean90

ocean90 Oct 3, 2017

Member

These are no longer required and can be removed.

This comment has been minimized.

@toolstack

toolstack Oct 3, 2017

Contributor

👍

@toolstack

toolstack Oct 3, 2017

Contributor

👍

Show outdated Hide outdated bin/locale-generator/locale-generator.php
$root_var_name = str_replace( '-', '_', $locale->variant_root );
// Output the first line to 'create' the GP_Locale object for this locale.
echo "\t\t\${$var_name} = new GP_Locale();\n"; // WPCS: XSS ok.

This comment has been minimized.

@ocean90

ocean90 Oct 3, 2017

Member

Remove all // WPCS: XSS ok. comments and add the bin directory as a exclude-pattern to phpcs.xml.

@ocean90

ocean90 Oct 3, 2017

Member

Remove all // WPCS: XSS ok. comments and add the bin directory as a exclude-pattern to phpcs.xml.

This comment has been minimized.

@toolstack

toolstack Oct 3, 2017

Contributor

👍

@toolstack

toolstack Oct 3, 2017

Contributor

👍

Show outdated Hide outdated bin/locale-generator/locale-generator.php
}
}
}
} // End foreach().

This comment has been minimized.

@ocean90

ocean90 Oct 3, 2017

Member

These are no longer required and can be removed.

@ocean90

ocean90 Oct 3, 2017

Member

These are no longer required and can be removed.

This comment has been minimized.

@toolstack

toolstack Oct 3, 2017

Contributor

👍

@toolstack

toolstack Oct 3, 2017

Contributor

👍

@@ -12,6 +12,9 @@
<dt><label for="project[description]"><?php _e( 'Description', 'glotpress' ); ?></label> <span class="ternary"><?php _e( 'can include HTML', 'glotpress' ); ?></span></dt>
<dd><textarea name="project[description]" rows="4" cols="40" id="project[description]"><?php echo esc_html( $project->description ); ?></textarea></dd>
<dt><label for="project[plurals_type]"><?php _e( 'Plurals Type', 'glotpress' ); ?></label></dt>
<dd><?php echo gp_plural_types_dropdown( 'project[plurals_type]', $project->plurals_type, array() ); // WPCS: XSS ok. ?></dd>

This comment has been minimized.

@ocean90

ocean90 Apr 8, 2018

Member

The // WPCS: XSS ok seems to be obsolete.

@ocean90

ocean90 Apr 8, 2018

Member

The // WPCS: XSS ok seems to be obsolete.

@ocean90

The current locale alignment doesn't match our code styling. Example:

<?php
$av = new GP_Locale();
$av->english_name                         = 'Avaric';
$av->native_name                          = 'авар мацӀ';
$av->text_direction                       = 'ltr';
$av->lang_code_iso_639_1                  = 'av';
$av->lang_code_iso_639_2                  = 'ava';
$av->slug                                 = 'av';
$av->nplurals                             = '2';
$av->plural_expression                    = 'n != 1';

produces:

-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 9 WARNINGS AFFECTING 9 LINES
-----------------------------------------------------------------------------------------------------------------
  2 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 22 spaces but found 1 space
  3 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 8 spaces but found 25 spaces
  4 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 9 spaces but found 26 spaces
  5 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 6 spaces but found 23 spaces
  6 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 1 space but found 18 spaces
  7 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 1 space but found 18 spaces
  8 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 16 spaces but found 33 spaces
  9 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 12 spaces but found 29 spaces
 10 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 3 spaces but found 20 spaces
-----------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------

It needs to be:

$av                      = new GP_Locale();
$av->english_name        = 'Avaric';
$av->native_name         = 'авар мацӀ';
$av->text_direction      = 'ltr';
$av->lang_code_iso_639_1 = 'av';
$av->lang_code_iso_639_2 = 'ava';
$av->slug                = 'av';
$av->nplurals            = '2';
$av->plural_expression   = 'n != 1';
$af->cldr_code = 'af';
$af->cldr_nplurals = '2';
$af->cldr_plural_expressions['one'] = 'n = 1 @integer 1 @decimal 1.0, 1.00, 1.000, 1.0000';
$af->cldr_plural_expressions['other'] = ' @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~0.9, 1.1~1.6, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …';

This comment has been minimized.

@ocean90

ocean90 Apr 8, 2018

Member

Is the leading whitespace required?

@ocean90

ocean90 Apr 8, 2018

Member

Is the leading whitespace required?

This comment has been minimized.

@toolstack

toolstack May 17, 2018

Contributor

I don't think so but it's in the original JSON file from the CLDR repo so I think it's safer to leave in.

@toolstack

toolstack May 17, 2018

Contributor

I don't think so but it's in the original JSON file from the CLDR repo so I think it's safer to leave in.

Show outdated Hide outdated gp-includes/formats/format-resx.php
@@ -162,6 +274,11 @@ private function add_schema_info() {
$this->line('-->', 1 );
}
/**
* Cteate the .resx schema declaration. .resx file have a standard scheam declaration.

This comment has been minimized.

@GaryJones

GaryJones Apr 9, 2018

Several typos here.

@GaryJones

GaryJones Apr 9, 2018

Several typos here.

This comment has been minimized.

@toolstack

toolstack May 17, 2018

Contributor

Fixed.

@toolstack

toolstack May 17, 2018

Contributor

Fixed.

Show outdated Hide outdated gp-includes/formats/format-resx.php
private function escape( $string ) {
$string = str_replace( array( '&', '<' ), array( '&amp;', '&lt;' ), $string );
return $string;
}
/**
* Cteate the .resx schema info. .resx file have a standard scheam block.

This comment has been minimized.

@GaryJones

GaryJones Apr 9, 2018

Several typos here.

@GaryJones

GaryJones Apr 9, 2018

Several typos here.

This comment has been minimized.

@toolstack

toolstack May 17, 2018

Contributor

Fixed.

@toolstack

toolstack May 17, 2018

Contributor

Fixed.

in the current version of phpcs (see https://github.com/squizlabs/PHP_CodeSniffer/issues/1731)
which breaks this when a single file name is passed to be checked (for example with TravisCI).
A fix has been committed and will be included in phpcs version 3.2, however this is no release

This comment has been minimized.

@GaryJones

GaryJones Apr 9, 2018

PHPCS 3.2 was released in December 2017, and the latest release is 3.2.3, with 3.3.0 not too far away. It would be reasonable to make ^3.2 the minimum version of PHPCS required for devs to contribute to GlotPress.

@GaryJones

GaryJones Apr 9, 2018

PHPCS 3.2 was released in December 2017, and the latest release is 3.2.3, with 3.3.0 not too far away. It would be reasonable to make ^3.2 the minimum version of PHPCS required for devs to contribute to GlotPress.

This comment has been minimized.

@toolstack

toolstack May 17, 2018

Contributor

This should have automatically taken care of itself, we just have to remove the extra lines now as they were only needed before 3.2 was released.

@toolstack

toolstack May 17, 2018

Contributor

This should have automatically taken care of itself, we just have to remove the extra lines now as they were only needed before 3.2 was released.

toolstack added some commits Jun 23, 2017

Add examples and number generator for cldr plurals.
Also update code differentiate between the types.

Re-order few/many to match CLDR order in the locales.
Fix the android export test case.
And add a minor comment to the locale generator.
Various updates.
Rename dropdown function and PHP CS rule additions.

Fix error.
First cut at stringdict support.
Import not yet implemented.

toolstack added some commits May 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment