Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chinese_permalink

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chinese_permalink

  • 1.3.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

Package last updated on 26 Oct 2011

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc