mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
I18N: Support loading .l10n.php translation files on their own.
Adjusts the translation file lookup in `WP_Textdomain_Registry` so that just-in-time translation loading works even if there is only a `.l10n.php` translation file without a corresponding `.mo` file. While language packs continue to contain both file types, this makes it easier to use translations in a project without having to deal with `.mo` or `.po` files. Props Chrystl. See #59656. git-svn-id: https://develop.svn.wordpress.org/trunk@57516 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=(n != 1);','messages'=>['This is a dummy plugin'=>'Das ist ein Dummy Plugin'],'language'=>'de_DE','x-generator'=>'Poedit 2.4.1'];
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=(n != 1);','messages'=>['This is a dummy plugin'=>'Este es un plugin dummy'],'language'=>'de_DE','x-generator'=>'Poedit 2.4.1'];
|
||||
12
tests/phpunit/data/plugins/internationalized-plugin-2.php
Normal file
12
tests/phpunit/data/plugins/internationalized-plugin-2.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Dummy Plugin 2
|
||||
Plugin URI: https://wordpress.org/
|
||||
Description: For testing purposes only. Only has an .l10n.php translation file.
|
||||
Version: 1.0.0
|
||||
Text Domain: internationalized-plugin
|
||||
*/
|
||||
|
||||
function i18n_plugin_2_test() {
|
||||
return __( 'This is a dummy plugin', 'internationalized-plugin-2' );
|
||||
}
|
||||
@@ -49,6 +49,7 @@ class Tests_L10n_LoadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
$wp_textdomain_registry = new WP_Textdomain_Registry();
|
||||
|
||||
unload_textdomain( 'internationalized-plugin' );
|
||||
unload_textdomain( 'internationalized-plugin-2' );
|
||||
unload_textdomain( 'internationalized-theme' );
|
||||
|
||||
parent::tear_down();
|
||||
@@ -86,6 +87,27 @@ class Tests_L10n_LoadTextdomainJustInTime extends WP_UnitTestCase {
|
||||
$this->assertTrue( $is_textdomain_loaded_after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 59656
|
||||
*
|
||||
* @covers ::is_textdomain_loaded
|
||||
*/
|
||||
public function test_plugin_translation_should_be_translated_with_only_an_l10n_php_file() {
|
||||
add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
require_once DIR_TESTDATA . '/plugins/internationalized-plugin-2.php';
|
||||
|
||||
$is_textdomain_loaded_before = is_textdomain_loaded( 'internationalized-plugin-2' );
|
||||
$actual_output = i18n_plugin_2_test();
|
||||
$is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-plugin-2' );
|
||||
|
||||
remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );
|
||||
|
||||
$this->assertFalse( $is_textdomain_loaded_before );
|
||||
$this->assertSame( 'Das ist ein Dummy Plugin', $actual_output );
|
||||
$this->assertTrue( $is_textdomain_loaded_after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 34114
|
||||
*
|
||||
|
||||
@@ -151,36 +151,46 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase {
|
||||
|
||||
public function data_domains_locales() {
|
||||
return array(
|
||||
'Non-existent plugin' => array(
|
||||
'Non-existent plugin' => array(
|
||||
'unknown-plugin',
|
||||
'en_US',
|
||||
false,
|
||||
),
|
||||
'Non-existent plugin with de_DE' => array(
|
||||
'Non-existent plugin with de_DE' => array(
|
||||
'unknown-plugin',
|
||||
'de_DE',
|
||||
false,
|
||||
),
|
||||
'Available de_DE translations' => array(
|
||||
'Available de_DE translations' => array(
|
||||
'internationalized-plugin',
|
||||
'de_DE',
|
||||
WP_LANG_DIR . '/plugins/',
|
||||
),
|
||||
'Available es_ES translations' => array(
|
||||
'Available es_ES translations' => array(
|
||||
'internationalized-plugin',
|
||||
'es_ES',
|
||||
WP_LANG_DIR . '/plugins/',
|
||||
),
|
||||
'Unavailable fr_FR translations' => array(
|
||||
'Unavailable fr_FR translations' => array(
|
||||
'internationalized-plugin',
|
||||
'fr_FR',
|
||||
false,
|
||||
),
|
||||
'Unavailable en_US translations' => array(
|
||||
'Unavailable en_US translations' => array(
|
||||
'internationalized-plugin',
|
||||
'en_US',
|
||||
false,
|
||||
),
|
||||
'Available de_DE translations (.l10n.php)' => array(
|
||||
'internationalized-plugin-2',
|
||||
'de_DE',
|
||||
WP_LANG_DIR . '/plugins/',
|
||||
),
|
||||
'Available es_ES translations (.l10n.php)' => array(
|
||||
'internationalized-plugin-2',
|
||||
'es_ES',
|
||||
WP_LANG_DIR . '/plugins/',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user