[WordPress] 外掛分享: LangBranch Shortcode

首頁外掛目錄 › LangBranch Shortcode
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
全新外掛
安裝啟用
尚無評分
1332 天前
最後更新
問題解決
PHP 7.4+ v1.0.1 上架:2022-07-29

內容簡介

什麼是LangBranch?

它是一個簡單的外掛,讓您可以使用像下面這樣的縮短碼(Shortcode),根據get_locale()顯示對應的內容語言版本。
`php
[langbranch aio en_US=”英文版” en_GB=”en_US” zh_TW=”中文版” ja_JP=”日本語版”]

[langbranch en_US]
只有get_locale()返回"en_US"時,這裡的內容才會顯示。
[/langbranch]
[langbranch en_US zh_TW]
只有get_locale()返回"en_US"或"zh_TW"時,這裡的內容才會顯示。
[/langbranch]
`

激勵

我一直在使用TranslatePress提供多語言體驗給訪客。
然而,每當我更新原始語言的內容時,我就會遺失翻譯的內容,直到我決定創建一個簡單的縮短碼來解決這個問題。

使用方法

AIO(1行)模式

“`php
[langbranch aio en_US=”英文版” en_GB=”en_US” zh_TW=”中文版” ja_JP=”日本語版”]
在langbranch主標記後添加`aio`,您可以在多種語言中設置一個特定的段落,並且如果您決定將某些語言共享給某些地區/國家,您可以直接在內容中輸入想要引用的地區/國家的代碼。例如,您可以將英國版與美國版設置為相同版本。

但是,如果分叉太深(堆疊超過5個),它將失敗。
請勿這樣做:
–1—||—2—||—3—||—4—||—5—||—6—> Oh no!
en_US -> en_GB -> en_AU -> en_HK -> zh_TW -> ja_JP

分開模式

“`php
[langbranch en_US]
只有get_locale()返回"en_US"時,這裡的內容才會顯示。
[/langbranch][langbranch en_US zh_TW]
只有get_locale()返回"en_US"或"zh_TW"時,這裡的內容才會顯示。
要非常直接的,但使用多個縮短碼時,建議您不要在[/langbranch]和[langbranch]之間加入斷行來防止意外出現斷行`被呈現。

可選步驟

所有由[langbranch]包含的內容都會被包含在<div class ="langbranch"></div>中呈現。
因此,如果您正在使用TranslatePress等自動機器翻譯功能,您可能希望排除所有選擇器.langbranch。

概括

這個"外掛"所做的事情非常簡單,它既沒有訪問文件系統,也沒有訪問數據庫。

但是,使用時仍有可能遇到一些問題。
在最壞的情況下,如果腳本產生錯誤,它會破壞您的網站。
如果發生這種情況,不要恐慌!
只需轉到wp-content/plugins目錄並刪除langbranch即可。

連結

訪問Github存儲庫以追蹤和報告問題。
訪問hollen9.com以獲取最新更新和想法。
請為我買杯咖啡以支持我的工作。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「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

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.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon