Skip to content

Commit

Permalink
Add Chinese table.
Browse files Browse the repository at this point in the history
Bump up version to 4.3.
  • Loading branch information
kagg-design committed Dec 1, 2019
1 parent fafbea8 commit c20c533
Show file tree
Hide file tree
Showing 17 changed files with 1,997 additions and 797 deletions.
8 changes: 4 additions & 4 deletions cyr-to-lat.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* Author: Sergey Biryukov, Mikhail Kobzarev, Igor Gergel
* Author URI: https://profiles.wordpress.org/sergeybiryukov/
* Requires at least: 5.1
* Tested up to: 5.2
* Version: 4.2.3
* Stable tag: 4.2.3
* Tested up to: 5.3
* Version: 4.3
* Stable tag: 4.3
*
* Text Domain: cyr2lat
* Domain Path: /languages/
Expand All @@ -28,7 +28,7 @@
/**
* Plugin version.
*/
define( 'CYR_TO_LAT_VERSION', '4.2.3' );
define( 'CYR_TO_LAT_VERSION', '4.3' );
}

if ( ! defined( 'CYR_TO_LAT_PATH' ) ) {
Expand Down
410 changes: 410 additions & 0 deletions includes/class-cyr-to-lat-conversion-tables.php

Large diffs are not rendered by default.

42 changes: 33 additions & 9 deletions includes/class-cyr-to-lat-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ class Cyr_To_Lat_Main {
*
* @var Cyr_To_Lat_Settings
*/
private $settings;
protected $settings;

/**
* Converter instance.
*
* @var Cyr_To_Lat_Converter
*/
private $converter;
protected $converter;

/**
* Cyr_To_Lat_WP_CLI instance.
*
* @var Cyr_To_Lat_WP_CLI
*/
private $cli;
protected $cli;

/**
* Cyr_To_Lat_ACF instance.
*
* @var Cyr_To_Lat_ACF
*/
private $acf;
protected $acf;

/**
* Cyr_To_Lat_Main constructor.
Expand Down Expand Up @@ -179,11 +179,7 @@ public function ctl_sanitize_filename( $filename, $filename_raw ) {
}

if ( seems_utf8( $filename ) ) {
if ( function_exists( 'mb_strtolower' ) ) {
$filename = mb_strtolower( $filename, 'UTF-8' );
} else {
$filename = Mbstring::mb_strtolower( $filename );
}
$filename = Mbstring::mb_strtolower( $filename );
}

return $this->transliterate( $filename );
Expand All @@ -210,6 +206,33 @@ private function fix_mac_string( $string ) {
return strtr( $string, $fix );
}

/**
* Split Chinese string by hyphens.
*
* @param string $string String.
* @param array $table Conversion table.
*
* @return string
*/
protected function split_chinese_string( $string, $table ) {
if ( ! $this->settings->is_chinese_locale() || Mbstring::mb_strlen( $string ) < 4 ) {
return $string;
}

$chars = Mbstring::mb_str_split( $string );
$string = '';

foreach ( $chars as $char ) {
if ( isset( $table[ $char ] ) ) {
$string .= '-' . $char . '-';
} else {
$string .= $char;
}
}

return $string;
}

/**
* Get transliteration table.
*
Expand All @@ -230,6 +253,7 @@ private function transliterate( $string ) {
$table = $this->get_filtered_table();

$string = $this->fix_mac_string( $string );
$string = $this->split_chinese_string( $string, $table );
$string = strtr( $string, $table );

if ( function_exists( 'iconv' ) ) {
Expand Down
59 changes: 56 additions & 3 deletions includes/class-cyr-to-lat-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package cyr-to-lat
*/

use Cyr_To_Lat\Symfony\Polyfill\Mbstring\Mbstring;

/**
* Class Cyr_To_Lat_Settings
*
Expand Down Expand Up @@ -211,6 +213,15 @@ public function init_form_fields() {
'supplemental' => '',
'default' => Cyr_To_Lat_Conversion_Tables::get( 'he_IL' ),
),
'zh_CN' => array(
'label' => __( 'zh_CN Table', 'cyr2lat' ),
'section' => 'zh_CN_section',
'type' => 'table',
'placeholder' => '',
'helper' => '',
'supplemental' => '',
'default' => Cyr_To_Lat_Conversion_Tables::get( 'zh_CN' ),
),
);
}

Expand Down Expand Up @@ -400,6 +411,12 @@ public function setup_sections() {
array( $this, 'cyr_to_lat_section' ),
self::PAGE
);
add_settings_section(
'zh_CN_section',
__( 'zh_CN Table', 'cyr2lat' ),
array( $this, 'cyr_to_lat_section' ),
self::PAGE
);
}

/**
Expand Down Expand Up @@ -626,7 +643,7 @@ public function field_callback( $arguments ) {
* @param string $key Setting name.
* @param mixed $empty_value Empty value for this setting.
*
* @return string The value specified for the option or a default value for the option.
* @return string|array The value specified for the option or a default value for the option.
*/
public function get_option( $key, $empty_value = null ) {
if ( empty( $this->settings ) ) {
Expand Down Expand Up @@ -740,7 +757,7 @@ public function load_plugin_textdomain() {
/**
* Get transliteration table.
*
* @return string
* @return array
*/
public function get_table() {
// List of locales: https://make.wordpress.org/polyglots/teams/.
Expand All @@ -750,7 +767,43 @@ public function get_table() {
$table = $this->get_option( 'iso9' );
}

return $table;
return $this->transpose_chinese_table( $table );
}

/**
* Is current locale a Chinese one.
*
* @return bool
*/
public function is_chinese_locale() {
$chinese_locales = [ 'zh_CN', 'zh_HK', 'zh_SG', 'zh_TW' ];

return in_array( get_locale(), $chinese_locales, true );
}

/**
* Transpose Chinese table.
*
* Chinese tables are stored in different way, to show them compact.
*
* @param array $table Table.
*
* @return array
*/
protected function transpose_chinese_table( $table ) {
if ( ! $this->is_chinese_locale() ) {
return $table;
}

$transposed_table = [];
foreach ( $table as $key => $item ) {
$hieroglyphs = Mbstring::mb_str_split( $item );
foreach ( $hieroglyphs as $hieroglyph ) {
$transposed_table[ $hieroglyph ] = $key;
}
}

return $transposed_table;
}

/**
Expand Down
Binary file modified languages/cyr2lat-ru_RU.mo
Binary file not shown.
72 changes: 41 additions & 31 deletions languages/cyr2lat-ru_RU.po
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: Cyr To Lat\n"
"POT-Creation-Date: 2019-06-23 11:48+0300\n"
"PO-Revision-Date: 2019-06-23 11:48+0300\n"
"POT-Creation-Date: 2019-12-01 15:25+0200\n"
"PO-Revision-Date: 2019-12-01 15:26+0200\n"
"Last-Translator: KAGG Design <info@kagg.eu>\n"
"Language-Team: KAGG Design\n"
"Language: ru_RU\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.3\n"
"X-Generator: Poedit 2.2.4\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"
Expand All @@ -20,16 +20,6 @@ msgstr ""
"X-Poedit-SearchPathExcluded-1: dist\n"
"X-Poedit-SearchPathExcluded-2: src\n"

#. translators: 1: Current PHP version number, 2: Cyr To Lat version, 3: Minimum required PHP version number
#: cyr-to-lat.php:85
#, php-format
msgid ""
"Your server is running PHP version %1$s but Cyr To Lat %2$s requires at "
"least %3$s."
msgstr ""
"На сервере установлен PHP версии %1$s, однако для Cyr To Lat %2$s требуется "
"хотя бы %3$s."

#. phpcs:enable
#: includes/background-processes/class-cyr-to-lat-post-conversion-process.php:67
msgid "Post slug converted:"
Expand Down Expand Up @@ -89,6 +79,16 @@ msgstr "Cyr To Lat начал конвертацию существующих я
msgid "Cyr To Lat has not found existing term slugs for conversion."
msgstr "Cyr To Lat не нашёл существующих ярлыков терминов для конвертации."

#. translators: 1: Current PHP version number, 2: Cyr To Lat version, 3: Minimum required PHP version number
#: includes/class-cyr-to-lat-requirements.php:50
#, php-format
msgid ""
"Your server is running PHP version %1$s but Cyr To Lat %2$s requires at "
"least %3$s."
msgstr ""
"На сервере установлен PHP версии %1$s, однако для Cyr To Lat %2$s требуется "
"хотя бы %3$s."

#: includes/class-cyr-to-lat-settings.php:121
msgid "View Cyr To Lat settings"
msgstr "Посмотреть настройки Cyr To Lat"
Expand All @@ -98,72 +98,82 @@ msgid "Settings"
msgstr "Настройки"

#: includes/class-cyr-to-lat-settings.php:134
#: includes/class-cyr-to-lat-settings.php:342
#: includes/class-cyr-to-lat-settings.php:360
msgid "ISO9 Table"
msgstr "Таблица ISO9"

#: includes/class-cyr-to-lat-settings.php:143
#: includes/class-cyr-to-lat-settings.php:348
#: includes/class-cyr-to-lat-settings.php:366
msgid "bel Table"
msgstr "Таблица bel"

#: includes/class-cyr-to-lat-settings.php:152
#: includes/class-cyr-to-lat-settings.php:354
#: includes/class-cyr-to-lat-settings.php:372
msgid "uk Table"
msgstr "Таблица uk"

#: includes/class-cyr-to-lat-settings.php:161
#: includes/class-cyr-to-lat-settings.php:360
#: includes/class-cyr-to-lat-settings.php:378
msgid "bg_BG Table"
msgstr "Таблица bg_BG"

#: includes/class-cyr-to-lat-settings.php:170
#: includes/class-cyr-to-lat-settings.php:366
#: includes/class-cyr-to-lat-settings.php:384
msgid "mk_MK Table"
msgstr "Таблица mk_MK"

#: includes/class-cyr-to-lat-settings.php:179
#: includes/class-cyr-to-lat-settings.php:372
#: includes/class-cyr-to-lat-settings.php:390
msgid "sr_RS Table"
msgstr "Таблица sr_RS"

#: includes/class-cyr-to-lat-settings.php:188
#: includes/class-cyr-to-lat-settings.php:396
msgid "ka_GE Table"
msgstr "Таблица ka_GE"

#: includes/class-cyr-to-lat-settings.php:188
#: includes/class-cyr-to-lat-settings.php:378
#: includes/class-cyr-to-lat-settings.php:197
#: includes/class-cyr-to-lat-settings.php:402
msgid "kk Table"
msgstr "Таблица kk"

#: includes/class-cyr-to-lat-settings.php:197
#: includes/class-cyr-to-lat-settings.php:384
#: includes/class-cyr-to-lat-settings.php:206
#: includes/class-cyr-to-lat-settings.php:408
msgid "he_IL Table"
msgstr "Таблица he_IL"

#: includes/class-cyr-to-lat-settings.php:261
#: includes/class-cyr-to-lat-settings.php:262
#: includes/class-cyr-to-lat-settings.php:215
#: includes/class-cyr-to-lat-settings.php:414
msgid "zh_CN Table"
msgstr "Таблица zh_CN"

#: includes/class-cyr-to-lat-settings.php:279
#: includes/class-cyr-to-lat-settings.php:280
msgid "Cyr To Lat"
msgstr "Cyr To Lat"

#. Admin panel title.
#: includes/class-cyr-to-lat-settings.php:282
#: includes/class-cyr-to-lat-settings.php:300
msgid "Cyr To Lat Plugin Options"
msgstr "Опции плагина Cyr To Lat"

#: includes/class-cyr-to-lat-settings.php:297
#: includes/class-cyr-to-lat-settings.php:315
msgid "Convert Existing Slugs"
msgstr "Конвертировать существующие ярлыки"

#: includes/class-cyr-to-lat-settings.php:303
#: includes/class-cyr-to-lat-settings.php:321
msgid "Donate"
msgstr "Пожертвовать"

#: includes/class-cyr-to-lat-settings.php:306
#: includes/class-cyr-to-lat-settings.php:324
msgid "Would you like to support the advancement of this plugin?"
msgstr "Хотите поддержать развитие этого плагина?"

#: includes/class-cyr-to-lat-settings.php:320
#: includes/class-cyr-to-lat-settings.php:338
msgid "Your appreciation"
msgstr "Ваша оценка"

#: includes/class-cyr-to-lat-settings.php:325
#: includes/class-cyr-to-lat-settings.php:343
msgid "Leave a ★★★★★ plugin review on WordPress.org"
msgstr "Оставьте ★★★★★ обзор плагина на WordPress.org"

Expand Down
Binary file modified languages/cyr2lat-sv.mo
Binary file not shown.
Loading

0 comments on commit c20c533

Please sign in to comment.