Skip to content

Use Google's Natural Language API to add support for intelligent word-wrapping for CJK languages.

License

Notifications You must be signed in to change notification settings

grow/grow-ext-budou

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
}

About

Use Google's Natural Language API to add support for intelligent word-wrapping for CJK languages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published