
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
h1. ChinesePermalink
This plugin adds a capability for ar model to create a seo permalink with your chinese text. It will translate your chinese text to english url based on google translate.
The permalink will be composed of id and the english value translated from chinese text.
For exmpale, title of post is '我是中国人', permalink of post is '1-i-am-a-chinese'
h2. Install
sudo gem install chinese_permalink
h2. Config
As google translator api begins to charge, I decide to use bing translator api, it's free. You have to add a config file to tell chinese_permalink what's your bing app id in config/chinese_permalink.yml
bing:
app_id: xxx
language: zh-cht (chinese traditional, default is zh-chs, chinese simplified)
h2. Example
1. Define chinese_permalink to model
class Post < ActiveRecord::Base
# create permalink by chinese title, default permalink column is "permalink"
chinese_permalink :title
end
Or
class Post < ActiveRecord::Base
# create permalink by chinese category and title
chinese_permalink [:category, :title]
end
Or
class Post < ActiveRecord::Base
# create permalink by chinese title, store permalink to column "slug_url"
chinese_permalink :title, :permalink_field => :slug_url
end
2. Generate migration
script/generate chinese_permalink_migration (table name) (permalink column name)
For example:
script/generate chinese_permalink_migration posts
Or
script/generate chinese_permalink_migration posts slug_url
3. Define ar to_param method
class Post < ActiveRecord::Base
def to_param
"#{id}-#{permalink}"
end
end
h2. Advance
You can add before_methods and after_methods to meet your business, for example:
class Post < ActiveRecord::Base
chinese_permalink :title, :before_methods => :parse_c_sharp
def parse_c_sharp(permalink)
permalink.gsub('C#', 'c-sharp')
end
end
class Post < ActiveRecord::Base
chinese_permalink :title, :after_methods => :parse_pg
def parse_pg(permalink)
permalink.gsub('Procter & Gamble', 'pg')
end
end
Copyright (c) 2009 Richard Huang (flyerhzm@gmail.com), released under the MIT license
FAQs
Unknown package
We found that chinese_permalink demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.