-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internationalize the plugin using Gutenberg's i18n library and scripts
- Loading branch information
1 parent
cced255
commit 5e6d8af
Showing
25 changed files
with
220 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"presets": ["@wordpress/default"] | ||
"presets": ["@wordpress/default"], | ||
"plugins": [ | ||
["@wordpress/babel-plugin-makepot", { "output": "languages/gcf.pot" }] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ scripts/*/build | |
node_modules | ||
gcf.zip | ||
.DS_Store | ||
svn | ||
svn | ||
languages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* Returns Jed-formatted localization data. | ||
* | ||
* @since 1.4.0 | ||
* | ||
* @param string $domain Translation domain. | ||
* | ||
* @return array | ||
*/ | ||
function gutenberg_custom_fields_get_jed_locale_data( $domain ) { | ||
$translations = get_translations_for_domain( $domain ); | ||
|
||
$locale = array( | ||
'' => array( | ||
'domain' => $domain, | ||
'lang' => is_admin() ? get_user_locale() : get_locale(), | ||
), | ||
); | ||
|
||
if ( ! empty( $translations->headers['Plural-Forms'] ) ) { | ||
$locale['']['plural_forms'] = $translations->headers['Plural-Forms']; | ||
} | ||
|
||
foreach ( $translations->entries as $msgid => $entry ) { | ||
$locale[ $msgid ] = $entry->translations; | ||
} | ||
|
||
return $locale; | ||
} | ||
|
||
/** | ||
* Registers the i18n script | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
function gutenberg_custom_fields_i18n_register() { | ||
$locale_data = gutenberg_custom_fields_get_jed_locale_data( 'gcf' ); | ||
$content = 'wp.i18n.setLocaleData( ' . json_encode( $locale_data ) . ', "gcf" );'; | ||
|
||
wp_register_script( 'gcf-i18n', null, array( 'wp-i18n' ) ); | ||
wp_script_add_data( 'gcf-i18n', 'data', $content ); | ||
} | ||
add_action( 'init', 'gutenberg_custom_fields_i18n_register' ); | ||
|
||
|
||
/** | ||
* Load plugin text domain for translations. | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
function gutenberg_custom_fields_load_plugin_textdomain() { | ||
load_plugin_textdomain( | ||
'gcf', | ||
false, | ||
plugin_basename( gutenberg_custom_fields_dir_path() ) . '/languages/' | ||
); | ||
} | ||
add_action( 'plugins_loaded', 'gutenberg_custom_fields_load_plugin_textdomain' ); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.