Skip to content
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

add new japanese language #210

Open
wants to merge 4 commits into
base: 3.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cache:
- '%LOCALAPPDATA%\Composer\files'

init:
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php71;%PATH%
- SET PATH=C:\Program Files\OpenSSL;C:\tools\php;%PATH%

environment:
matrix:
Expand All @@ -17,22 +17,19 @@ install:
- cinst -y OpenSSL.Light
- sc config wuauserv start= auto
- net start wuauserv
- cinst -y php
- cd c:\tools\php71
- cinst -y php --params "/InstallDir:C:\tools\php"
- cd C:\tools\php
- copy php.ini-production php.ini /Y
- echo date.timezone="UTC" >> php.ini
- echo extension_dir=ext >> php.ini
- echo extension=php_openssl.dll >> php.ini
- echo extension=php_mbstring.dll >> php.ini
- echo extension=php_fileinfo.dll >> php.ini
- echo memory_limit=1G >> php.ini
- cd c:\projects\cocur\slugify
- php -r "readfile('http://getcomposer.org/installer');" | php
- cd %APPVEYOR_BUILD_FOLDER%
- php -r "readfile('https://getcomposer.org/installer');" | php
- php composer.phar update %COMPOSER_FLAGS% --no-interaction --no-progress

test_script:
- cd c:\projects\cocur\slugify
- vendor\bin\phpunit.bat --verbose
- cd %APPVEYOR_BUILD_FOLDER%
- vendor\bin\phpunit --verbose --colors=always

notifications:
- provider: Webhook
Expand Down
166 changes: 166 additions & 0 deletions Resources/rules/japanese
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"あ": "a",
"ア": "a",
"か": "ka",
"カ": "ka",
"さ": "sa",
"サ": "sa",
"た": "ta",
"タ": "ta",
"な": "na",
"ナ": "na",
"は": "ha",
"ハ": "ha",
"ま": "ma",
"マ": "ma",
"や": "ya",
"ヤ": "ya",
"ら": "ra",
"ラ": "ra",
"わ": "wa",
"ワ": "wa",
"が": "ga",
"ざ": "za",
"だ": "da",
"ば": "ba",
"ぱ": "pa",

"い": "i",
"イ": "i",
"き": "ki",
"キ": "ki",
"し": "shi",
"シ": "shi",
"ち": "chi",
"チ": "chi",
"に": "ni",
"ニ": "ni",
"ひ": "hi",
"ヒ": "hi",
"み": "mi",
"ミ": "mi",
"り": "ri",
"リ": "ri",
"ゐ": "wi",
"ヰ": "wi",
"ぎ": "gi",
"じ": "dji",
"ぢ": "ji",
"び": "bi",
"ぴ": "pi",

"う": "u",
"ウ": "u",
"く": "ku",
"ク": "ku",
"す": "su",
"ス": "su",
"つ": "tsu",
"ツ": "tsu",
"ぬ": "nu",
"ヌ": "nu",
"ふ": "fu",
"フ": "fu",
"む": "mu",
"ム": "mu",
"ゆ": "yu",
"ユ": "yu",
"る": "ru",
"ル": "ru",
"ぐ": "gu",
"ず": "zu",
"づ": "dzu",
"ぶ": "bu",
"ぷ": "pu",

"え": "e",
"エ": "e",
"け": "ke",
"ケ": "ke",
"せ": "se",
"セ": "se",
"て": "te",
"テ": "te",
"ね": "ne",
"ネ": "ne",
"へ": "he",
"ヘ": "he",
"め": "me",
"メ": "me",
"れ": "re",
"レ": "re",
"ゑ": "we",
"ヱ": "we",
"げ": "ge",
"ぜ": "ze",
"で": "de",
"べ": "be",
"ぺ": "pe",

"お": "o",
"オ": "o",
"こ": "ko",
"コ": "ko",
"そ": "so",
"ソ": "so",
"と": "to",
"ト": "to",
"の": "no",
"ノ": "no",
"ほ": "ho",
"ホ": "ho",
"も": "mo",
"モ": "mo",
"よ": "yo",
"ヨ": "yo",
"ろ": "ro",
"ロ": "ro",
"を": "wo",
"ヲ": "wo",
"ん": "n",
"ン": "n",
"ご": "go",
"ぞ": "zo",
"ど": "do",
"ぼ": "bo",
"ぽ": "po",

"きゃ": "kya",
"しゃ": "sha",
"ちゃ": "cha",
"にゃ": "nya",
"ひゃ": "hya",
"みゃ": "mya",
"りゃ": "rya",
"ぎゃ": "gya",
"じゃ": "ja",
"ぢゃ": "ja",
"びゃ": "bya",
"ぴゃ": "pya",

"きゅ": "kyu",
"しゅ": "shu",
"ちゅ": "chu",
"にゅ": "nyu",
"ひゅ": "hyu",
"みゅ": "myu",
"りゅ": "ryu",
"ぎゅ": "gyu",
"じゅ": "ju",
"ぢゅ": "ju",
"びゅ": "byu",
"ぴゅ": "pyu",

"きょ": "kyo",
"しょ": "sho",
"ちょ": "cho",
"にょ": "nyo",
"ひょ": "hyo",
"みょ": "myo",
"りょ": "ryo",
"ぎょ": "gyo",
"じょ": "jo",
"ぢょ": "jo",
"びょ": "byo",
"ぴょ": "pyo"
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"pimple/pimple": "~1.1",
"plumphp/plum": "~0.1",
"silex/silex": "~1.3",
"symfony/config": "~2.4|~3.0",
"symfony/dependency-injection": "~2.4|~3.0",
"symfony/http-kernel": "~2.4|~3.0",
"symfony/config": "~2.4|~3.0|~4.0",
"symfony/dependency-injection": "~2.4|~3.0|~4.0",
"symfony/http-kernel": "~2.4|~3.0|~4.0",
"twig/twig": "~1.26|~2.0",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-servicemanager": "~2.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/CocurSlugifyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function load(array $configs, ContainerBuilder $container)
}

// Extract slugify arguments from config
$slugifyArguments = array_intersect_key($config, array_flip(['lowercase', 'separator', 'regexp', 'rulesets']));
$slugifyArguments = array_intersect_key($config, array_flip(['lowercase', 'trim', 'strip_tags', 'separator', 'regexp', 'rulesets']));

$container->setDefinition('cocur_slugify', new Definition('Cocur\Slugify\Slugify', [$slugifyArguments]));
$container
Expand Down
1 change: 1 addition & 0 deletions src/Bridge/Symfony/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function getConfigTreeBuilder()
->children()
->booleanNode('lowercase')->end()
->booleanNode('trim')->end()
->booleanNode('strip_tags')->end()
->scalarNode('separator')->end()
->scalarNode('regexp')->end()
->arrayNode('rulesets')->prototype('scalar')->end()
Expand Down
5 changes: 5 additions & 0 deletions src/Slugify.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Slugify implements SlugifyInterface
'separator' => '-',
'lowercase' => true,
'trim' => true,
'strip_tags' => false,
'rulesets' => [
'default',
// Languages are preferred if they appear later, list is ordered by number of
Expand Down Expand Up @@ -111,6 +112,10 @@ public function slugify($string, $options = null)
$rules = $this->rules;
}

$string = ($options['strip_tags'])
? strip_tags($string)
: $string;

$string = strtr($string, $rules);
unset($rules);

Expand Down
10 changes: 10 additions & 0 deletions tests/Bridge/Symfony/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testAll()
$configs = [
[
'lowercase' => true,
'strip_tags' => false,
'separator' => '_',
'regexp' => 'abcd',
'rulesets' => ['burmese', 'hindi']
Expand All @@ -39,6 +40,15 @@ public function testLowercaseOnlyAcceptsBoolean()
$this->process($configs);
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
*/
public function testStripTagsOnlyAcceptsBoolean()
{
$configs = [['strip_tags' => 'abc']];
$this->process($configs);
}

/**
* Processes an array of configurations and returns a compiled version.
*
Expand Down
4 changes: 4 additions & 0 deletions tests/SlugifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ public function slugifyOptionsArray()

$this->assertEquals('file-name', $this->slugify->slugify('file name '));
$this->assertEquals('file-name-', $this->slugify->slugify('file name ', ['trim' => false]));

$this->assertEquals('file-name', $this->slugify->slugify('<file name'));
$this->assertEquals('p-file-p-foo-a-href-bar-name-a', $this->slugify->slugify('<p>file</p><!-- foo --> <a href="#bar">name</a>'));
$this->assertEquals('file-name', $this->slugify->slugify('<p>file</p><!-- foo --> <a href="#bar">name</a>', ['strip_tags' => true]));
}

/**
Expand Down