
Security News
libxml2 Maintainer Ends Embargoed Vulnerability Reports, Citing Unsustainable Burden
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
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
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.