666: Add CLDR support #784
Conversation
A couple of notes on the current state of this:
|
Really happy to see this PR. Left a few comments on a few very minor issues spotted while taking a quick look |
/* | ||
* Get the CLDR Data. | ||
* | ||
* By defualt it is read from the plurals.json file in the current directory, you can download |
// Create a working locales object. | ||
$locales = new GP_Locales; | ||
|
||
// Run through the locales and see if we can find a mathcing CLDR locale. |
@@ -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; |
toolstack
on Jul 10, 2017
Author
Contributor
Yes, but only because it fixes an existing bug in the test case.
* | ||
* @return string HTML markup for a select element. | ||
*/ | ||
function gp_plurals_dropdown( $name_and_id, $selected_plural_type = null, $attrs = array() ) { |
@@ -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> |
ocean90
on Oct 3, 2017
Member
gp_plurals_dropdown()
should be added to customAutoEscapedFunctions
in phpcs.xml.
} // End foreach(). | ||
|
||
// Add some space between locales for easier reading. | ||
echo "\n"; // WPCS: XSS ok. |
toolstack
on Oct 3, 2017
Author
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.
} | ||
} | ||
} | ||
} // End foreach(). |
$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. |
ocean90
on Oct 3, 2017
Member
Remove all // WPCS: XSS ok.
comments and add the bin directory as a exclude-pattern to phpcs.xml.
} | ||
} | ||
} | ||
} // End foreach(). |
2a41a26
to
5a3ec10
44f8127
to
e171d3a
@@ -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> |
The current locale alignment doesn't match our code styling. Example:
produces:
It needs to be:
|
$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, …'; |
toolstack
on May 17, 2018
Author
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.
@@ -162,6 +274,11 @@ private function add_schema_info() { | |||
$this->line('-->', 1 ); | |||
} | |||
|
|||
/** | |||
* Cteate the .resx schema declaration. .resx file have a standard scheam declaration. |
private function escape( $string ) { | ||
$string = str_replace( array( '&', '<' ), array( '&', '<' ), $string ); | ||
return $string; | ||
} | ||
|
||
|
||
/** | ||
* Cteate the .resx schema info. .resx file have a standard scheam block. |
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 |
GaryJones
on 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.
toolstack
on May 17, 2018
Author
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.
dcbfaf9
to
83b45fe
And add a minor comment to the locale generator.
Rename dropdown function and PHP CS rule additions. Fix error.
Import not yet implemented.
Now appends the code around the locales list to make life easier.
To create no-variants version of the locales file and also write both out to files instead of the console. Also make a backup just in case before deleting the old file.
7264bcb
to
e7c0296
Resolves #666.