Comments (14)
You just need to add the corresponding rules.
from slugify.
would be interested in this too, how would you go about it? @dmyers did you manage it?
from slugify.
I have little to no knowledge about Chinese, but as far as I understand that Chinese doesn't really have what we call letters. That is, you cannot really transliterate a Chinese symbol into an ASCII character (or a series of characters), because Chinese characters are basically words (or at least part of words). Again I'm not 100% sure.
Take a look at FaSlugify (which seems to be based on this library for Farsi/Persian. This project includes another project called finglify which translates a Persian/Farsi word into latin characters. It includes a massive list of words. I guess that a Slugify for Chinese would also need such a list.
from slugify.
I have solved it kind of...
if (!function_exists('slugify')) {
/**
* Slugify string for urls
* @param $str
* @param string $separator
* @param string $locale
* @param bool $lowercase
* @return string
*/
function slugify($str, $separator = "-", $locale = 'en', $lowercase = false)
{
if (in_array($locale, ['zh'])) {
$str = transliterator_transliterate('Any-Latin', $str);
}
$slugify = new Slugify(null, array('lowercase' => $lowercase));
$slugify->addRules(
[
'א' => '',
'ב' => 'v',
'ב' => 'b',
'ג' => 'g',
'ג׳' => 'j',
'ד' => 'd',
'ד׳' => 'dh',
'ה' => 'h',
'ו' => 'v',
'ז' => 'z',
'ז׳' => 'zh',
'ח' => 'h',
'ט' => 't',
'י' => 'y',
'כ' => 'k',
'ך' => 'kh',
'ל' => 'l',
'מ' => 'm',
'ם' => 'm',
'נ' => 'n',
'ן' => 'n',
'ס' => 's',
'ע' => '',
'פ' => 'f',
'ף' => 'f',
'צ' => 'ts',
'ץ' => 'ts',
'ץ׳' => 'tsh',
'ק' => 'k',
'ר' => 'r',
'ש' => 's',
'ת' => 't'
]
);
return $slugify->slugify($str, $separator);
}
}
This adds rules for Hebrew and in case of Chinese it does transliterate but you have to send 'zh' $locale flag to the function.
Also update your composer and add:
"require": {
"ext-intl": "*",
from slugify.
<?php
preg_match("/\p{Han}+/u", 'test中文', $result);
var_dump($result);
from slugify.
Interesting question for I will sooner or later need this. After some research I have found this solution: http://pastebin.com/zZfci0Dz. The URL won't look nice but it is re-translatable from UTF-8 to Chinese without a loss.
There are easier solutions but they are not reliable and even dangerous. Read this first reply to understand why: http://stackoverflow.com/questions/5998607/conversion-from-simplified-to-traditional-chinese. You could run into problems. Something better to avoid as a web-designer. Use numbered url's instead.
from slugify.
$slugify = new \Cocur\Slugify\Slugify();
echo $slugify->slugify('中文');
echo empty, should be unchanged string '中文'.
from slugify.
+1 for the addition of the Chinese/pinyin
from slugify.
In order to make it Chinese/pinyin just modify Chinese string with
$str = transliterator_transliterate('Any-Latin', $str);
don't forget php requires "ext-intl": "*",
from slugify.
I suppose it could be easy to implement using a class like this as an addon: https://github.com/jifei/Pinyin/blob/master/Pinyin.php
from slugify.
Added Chinese support (pinyin): #158
from slugify.
#158 PR still not approved -- any progress? Thanks!
from slugify.
I don't know why checks are not successful, but it works: https://getsongbpm.com/artist/zhoujie/3vJn
Unless someone can tell me what's wrong with conflicting files, you'll have to add Chinese rules manually and generate your own set of rules (like i did in the example above) using #158 .
from slugify.
Fixed by #195
from slugify.
Related Issues (20)
- Generated ruleset different from the json file HOT 1
- Symfony Bundle ignores ruleset HOT 1
- Problem with combining characters HOT 2
- There is any options to convert in Unicode symbols to description HOT 3
- User Deprecated HOT 5
- Issue with usage, example doesnt work after installing with composer HOT 3
- how to get slug without translation HOT 1
- Laravel 9 Support HOT 3
- Sign « changes on quot HOT 1
- Split DefaultRules into deparate files
- Add command-line interface to this package? HOT 1
- release for php 8.2 HOT 2
- Remove reserved characters like ­ and
- New release does not work on PHP 7.4 HOT 2
- The version 4.4.0 have been removed from Packagist? HOT 3
- Requirements Version 4.5 HOT 2
- version 4.5.0 is not compatible with PHP 7 although mentioned in packagist HOT 3
- Czech rules missing several characters
- Syntax error, unexpected '|', expecting variable {t_variable} HOT 3
- Issue with Php Composer (Slugify)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slugify.