這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

LangBranch Shortcode

描述

What is LangBranch

It’s a simple plugin enable you to use a shortcode like below to display correspond language version of content based on get_locale().
`php
[langbranch aio en_US=”English version” en_GB=”en_US” zh_TW=”中文版本” ja_JP=”日本語バージョン”]

[langbranch en_US]
Content here will only be displayed if get_locale() returns “en_US”.
[/langbranch]
[langbranch en_US zh_TW]
Content here will only be displayed if get_locale() returns “en_US” or “zh_TW”.
[/langbranch]
`

Motivation

I’ve been using TranslatePress to provide multi locale experience for visiters.
However, I had been suffering from losting translated content once I update original language’s content, until I decided to create a simple shortcode to solve this problem.

Usages

AIO (1-liner) Mode

“`php
[langbranch aio en_US=”English version” en_GB=”en_US” zh_TW=”中文版本” ja_JP=”日本語バージョン”]
By appendingaio` after langbranch main tag, you can setup one specific paragraph in several languages, and if you decide that some locale user to share the same language, you can just type the locale code you want to refer to directly in content. For example, you can make UK version the same as US version.

However, if LangBranch go too deep (chain over 5 stacks) it will fail.
Don’t do this:
–1—||—2—||—3—||—4—||—5—||—6—> Oh no!
en_US -> en_GB -> en_AU -> en_HK -> zh_TW -> ja_JP

Seperate Mode

“`php
[langbranch en_US]
Content here will only be displayed if get_locale() returns “en_US”.
[/langbranch][langbranch en_US zh_TW]
Content here will only be displayed if get_locale() returns “en_US” or “zh_TW”.
這裡的內容,只有當 get_locale() 回傳 “en_US” 或 “zh_TW” 才會顯示。
[/langbranch]
Very straight forward, isn't?
But when using several shortcodes, I would suggest you don't put a linebreak between
[/langbranch]and[langbranch], in order to prevent unwanted linebreak
` being rendered.

Optional step

All contents enclosed by [langbranch] will be rendered enclosed by <div class="langbranch"></div>
So if you are using auto machine translating like TranslatePress offers, you may want to exclude all selector .langbranch.

Recaps

What this “plugin” do is very simple, it doesn’t has access to either filesystem or database.

However, you still have chance to encounter some issues while using it.
For the worst case, it breaks your site up if script produce error.
If that happen, do not be panic!
Just go to your wp-content/plugins directory and delete langbranch and you shall be fine.

Links

Visit Github repo for issues tracking and reporting.
Visit hollen9.com for latest updates and thoughts.
Buy me a coffee for supporting my works.

評價

There are no reviews for this plugin.

貢獻者及開發者

“LangBranch Shortcode” 是一個開源的軟體。以下的人對這個外掛作出了貢獻。

貢獻者

將 LangBranch Shortcode 外掛本地化為台灣繁體中文版。

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

修改日誌

1.01

  • Check array’s key before accessing it in order to avoid PHP notice message.

1.0

  • Init push