Use Google's Natural Language API to add support for intelligent word-wrapping for CJK languages.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
budou_ext
example
.gitignore
.travis.yml
LICENSE
README.md
setup.py

README.md

grow-ext-budou

Build Status

Budou extension for Grow.

Concept

Installs a filter into the Jinja2 environment that uses the Google Cloud Natural Language API to analyze text and insert <span> tags into HTML for intelligent word wrapping. The filter only activates when a page is being rendered in a supported language. Supported language identifiers:

  • ja
  • ko
  • zh
  • zh_Hans
  • zh_Hant

For more information on Budou, see the google/budou repository.

NOTE: Budou requires authentication to the Google Cloud Natural Language API. You will have to authorize Grow to access this API, or use a service account on a Google Cloud project where the API is enabled.

Usage

Initial setup

  1. Create an extensions.txt file within your pod.
  2. Add to the file: git+git://github.com/grow/grow-ext-budou
  3. Ensure .gitignore contains extensions.
  4. Run grow install.
  5. Add the following section to podspec.yaml:
extensions:
  jinja2:
  - extensions.budou_ext.BudouExtension

In templates

# Append the budou filter.
{{_("I will eat rice at Roppongi Hills.")|budou}}

# Outputs the following HTML.
<span class="ww">六本木</span><span class="ww">ヒルズに</span><span
class="ww">います。</span>

In CSS

Budou works by wrapping elements that should not be wrapped in a <span class="ww"> element. Add the following CSS to prevent these elements from wrapping.

.ww {
  display: inline-block;
}