[WordPress] 外掛分享: LangBranch Shortcode

前言介紹

  • 這款 WordPress 外掛「LangBranch Shortcode」是 2022-07-29 上架。 目前已經下架不再更新,不建議安裝使用。
  • 目前尚無安裝啟用數,是個很新的外掛。如有要安裝使用,建議多測試確保功能沒問題!
  • 上一次更新是 2022-07-30,距離現在已有 1306 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
  • 尚未有人給過這款外掛評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

hollen9 |

外掛標籤

locale | language | shortcode | translate | TranslatePress |

內容簡介

什麼是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以獲取最新更新和想法。
請為我買杯咖啡以支持我的工作。

原文外掛簡介

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.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「LangBranch Shortcode」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


最新版本

延伸相關外掛(你可能也想知道)

  • AI Translation For TranslatePress 》TranslatePress 自動機器翻譯外掛, , 與 TranslatePress 外掛一同安裝此插件,輕鬆節省你的時間。, , , 免費版本支援 Yandex 翻譯小部件。, 專業版 💎 支援 G...。
  • HHG for TranslatePress 》總結文案:, HHG for TranslatePress 是一個增強外掛,用於擴展 TranslatePress 多語言外掛的自動翻譯功能。它整合了主流的 AI 翻譯引擎,如 Google Gemini、...。
  • Hollisho Integration with DeepSeek for TranslatePress 》Hollisho Integration with DeepSeek for TranslatePress 是一个TranslatePress插件的扩展,它为TranslatePress添加了DeepSeek API支持。通过这个插件,您可...。
  • Ho YouDao Translate For TranslatePress 》Ho YouDao Translate For TranslatePress 是一个TranslatePress插件的扩展,它为TranslatePress添加了有道翻译API支持。通过这个插件,您可以使用有道翻译的A...。
  • TranslateX for TranslatePress 》<!DOCTYPE html>, <html>, <body>, , <h2>外掛總結:</h2>, <p>這個外掛將 TranslateX 自動翻譯 API,一個強大的神經機...。
  • URL Export Addon for TranslatePress 》總結:「URL Export Addon for TranslatePress」是一個 WooCommerce 外掛程式,可協助使用 TranslatePress 的店家將產品網址在所有翻譯語言中匯出為 CSV 檔案...。

文章
Filter
Apply Filters
Mastodon