Skip to content

liquid-utilities/includes-translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Includes Translate

Liquid utility that includes Google Translate HTML and JS code

Byte size of includes-translate Open Issues Open Pull Requests Latest commits Includes Translate Demos



Quick Start

Change current working directory to the repository that will be utilizing this project, and checkout your gh-pages branch if available...

cd ~/git/hub/__org_name__/__repository__


git checkout gh-pages

Add this project as a Git submodule...

mkdir -vp _includes/modules


git submodule add\
 -b master --name "includes-translate"\
 "https://github.com/liquid-utilities/includes-translate.git"\
 "_includes/modules/includes-translate"

Your ReadMe File

Suggested additions for your ReadMe.md file so everyone has a good time with submodules

Clone with the following to avoid incomplete downloads


    git clone --recurse-submodules <url-for-your-project>


Update/upgrade submodules via


    git submodule update --init --merge --recursive

Utilize Includes Translate

Include the Liquid script within a Layout file...

_layouts/default.html

<!--
  Source: https://raw.githubusercontent.com/jekyll/minima/v2.5.0/_layouts/default.html
  License: MIT
  Modified_For: liquid-utilities/includes-translate
-->
<!DOCTYPE html>
<html lang="{{ page.lang | default: site.lang | default: "en" }}">
  {%- include head.html -%}

  <body>
    {%- include header.html -%}

    <main class="page-content" aria-label="Content">
      <div class="wrapper">
        {% include modules/includes-translate/includes-translate.html %}
        {{ content }}
      </div>
    </main>

    {%- include footer.html -%}

  </body>

</html>

Note; depending upon theme choice it may be more organized to include code from this project within a header.html file, eg. _includes/header.html

Define site defaults...

_config.yaml

page:
  translate_id: translate_selection
  language: en
  translate_callback: google_translate_callback
  auto_translate: false

Individual posts may overwrite site defaults...

_posts/2019-08-16-hello-lifeforms.md

---
layout: post
title: "Hello Lifeforms"
date: 2019-08-16 13:58:05 -0700
categories: posts

language: es
auto_translate: true
---


Ejemplo de contenido de la página que se traducirá.

Commit and Push

git add README.md
git add .gitmodules
git add _config.yaml
git add _includes/modules/includes-translate
git add _layouts/default.html


## Add any changed files too


git commit -F- <<'EOF'
:heavy_plus_sign: Adds `liquid-utilities/includes-translate#1` submodule



**Additions**


- `.gitmodules`, tracks submodules AKA Git within Git _fanciness_

- `README.md`, updates installation and updating guidance

- `_layouts/modules/includes-translate`, injects JavaScript configs for translating page via Google Translate
EOF


git push origin gh-pages

🎉 Excellent 🎉 your site is now ready to begin unitizing code from this repository!


Notes

{% include %} parameters, and _config.yaml or _posts/_pages Frontmatter, may accept the following customizations;

  • translate_id string, HTML id that Google Translate script should inject option and select elements into; defaults to "translate_selection"

  • language string, language two letter code that pages are written in; defaults to "en"

  • translate_callback string, name of JavaScript function that Google Translate should call when a language option is chosen; defaults to "google_translate_callback"

  • auto_translate boolean, if true will add JavaScript function and event listener that will automatically select preferred language if detectable; defaults to false

  • disable_translate boolean, if true will disable all features of includes-translate within page/post or entire site; defaults to false


Because this project is a script that may be included, it is possible to translate select pages or posts instead of modifying site template files, eg...

_posts/2020-03-05-test-automatic-translation.md

---
layout: post
title: "Test Automatic Translation"
date: 2020-03-05 12:58:05 -0700
categories: posts

translate_id: translate_selection
translate_callback: google_translate_callback
language: ja
auto_translate: true
---
{% include modules/includes-translate/includes-translate.html %}


翻訳するページコンテンツの例。

Attribution


License

Legal bits of Open Source software

Includes Translate documentation on how things like this could be utilized
Copyright (C) 2022  S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation; version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

About

Liquid utility that includes Google Translate HTML and JS code

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages