Add translation support

master
rubenwardy 2017-08-26 16:40:30 +01:00
parent c8ac4dfd32
commit e81778f561
25 changed files with 96 additions and 77 deletions

View File

@ -21,12 +21,21 @@ fit my idea of quality.
## Finding your way around ## Finding your way around
* _data/ - Contains the navigation bar file. * `_data/` - Contains the navigation bar file.
(a list of links and link text for the navbar.) (a list of links and link text for the navbar.)
* _includes/ - Contains HTML templates. * `_includes/` - Contains HTML templates.
* _layouts/ - You can safely ignore this. * `_layouts/` - You can safely ignore this.
* static/ - CSS, images, scripts. * `static/` - CSS, images, scripts.
* chapters/ - Markdown files for each chapter. * `<lang>/`
* `chapters/` - Markdown files for each chapter.
## Adding a new language
* Add entry to `_data/languages.yml`
* Copy links_en, and customise it for your language
* Add your language to the if else in `_includes/header.html`
* Copy en/ to your language code
* Translate your language code folder
## Using Jeykll ## Using Jeykll

3
_data/languages.yml Normal file
View File

@ -0,0 +1,3 @@
- code: en
name: English (UK)
cta: This book is available in English

View File

@ -80,6 +80,3 @@
link: chapters/readmore.html link: chapters/readmore.html
- hr: true - hr: true
- title: Lua Modding API Reference
link: lua_api.html

View File

@ -9,20 +9,34 @@
<meta name="author" content="rubenwardy"> <meta name="author" content="rubenwardy">
</head> </head>
<body> <body>
{% assign pathsplit = page.dir | split: '/' %}
{% assign language = pathsplit[1] %}
{% if language == "en" %}
{% assign links = site.data.links_en %}
{% else %}
{% assign language = "en" %}
{% assign links = site.data.links_en %}
{% endif %}
<ul id="navbar"> <ul id="navbar">
{% for link in site.data.links %} {% for link in links %}
{% if link.hr %} {% if link.hr %}
{% assign hr = true %} {% assign hr = true %}
{% else %} {% else %}
<li><a href="{{ page.root }}{{ link.link }}" <li><a href="{{ page.root }}{{ language }}/{{ link.link }}"
class="{% if page.title == link.title %}selected{% endif %}{% if hr %} hr {% endif %}"> class="{% if page.title == link.title %}selected{% endif %}{% if hr %} hr {% endif %}">
{% if link.num %} {{ link.num }} - {% endif %} {% if link.num %} {{ link.num }} - {% endif %}
{{ link.title }}</a></li> {{ link.title }}</a></li>
{% assign hr = false %} {% assign hr = false %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<li><a href="{{ page.root }}lua_api.html">Lua Modding API Reference</a></li>
<li><a href="https://github.com/rubenwardy/minetest_modding_book/archive/examples.zip">Download Examples</a></li> <li><a href="https://github.com/rubenwardy/minetest_modding_book/archive/examples.zip">Download Examples</a></li>
<li><a id="printable">Printable Version</a></li> <li><a id="printable">Printable Version</a></li>
</ul> </ul>
<div id="page"> <div id="page">
<h1>{{ page.title }}</h1> <h1>{{ page.title }}</h1>

View File

@ -1,7 +1,7 @@
--- ---
title: Active Block Modifiers title: Active Block Modifiers
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Chat and Commands title: Chat and Commands
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Complex Chat Commands title: Complex Chat Commands
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Creating Textures title: Creating Textures
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Folder Structure title: Folder Structure
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Formspecs title: Formspecs
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: HUD title: HUD
layout: default layout: default
root: ../ root: ../../
--- ---
<div class="notice"> <div class="notice">

View File

@ -1,7 +1,7 @@
--- ---
title: Inventories title: Inventories
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: ItemStacks title: ItemStacks
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Lua Scripts title: Lua Scripts
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Node Drawtypes title: Node Drawtypes
layout: default layout: default
root: ../ root: ../../
--- ---
<div class="notice"> <div class="notice">

View File

@ -1,7 +1,7 @@
--- ---
title: Node Metadata title: Node Metadata
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Nodes, Items, and Crafting title: Nodes, Items, and Crafting
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Player Physics title: Player Physics
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Privileges title: Privileges
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,7 +1,7 @@
--- ---
title: Read More title: Read More
layout: default layout: default
root: ../ root: ../../
--- ---
## List of Resources ## List of Resources

View File

@ -1,7 +1,7 @@
--- ---
title: Releasing a Mod title: Releasing a Mod
layout: default layout: default
root: ../ root: ../../
--- ---
## Introduction ## Introduction

View File

@ -1,14 +1,14 @@
--- ---
title: Introduction title: Introduction
permalink: index.html
layout: default layout: default
root: ../
--- ---
Welcome Welcome
------- -------
Minetest uses Lua scripts to provide modding support. Minetest uses Lua scripts to provide modding support.
This online book aims to teach you how to create your own mods, This online book aims to teach you how to create your own mods,
starting from the basics. starting from the basics.
### What you will need ### What you will need

36
index.html Normal file
View File

@ -0,0 +1,36 @@
---
layout: none
---
<html>
<head>
<title>Redirecting...</title>
</head>
<body>
<script>
var languages = {{ site.data.languages | jsonify }};
function getLanguage() {
var userLang = navigator.language || navigator.userLanguage;
for (var i = 0; i < languages.length; i++) {
var lang = languages[i];
console.log(lang.code + " vs " + userLang);
if (userLang.indexOf(lang.code) == 0) {
return lang;
}
}
return null;
}
var language = getLanguage() || languages[0];
console.log('<a href="/' + language.code +
'/index.html">Redirecting to the ' + language.name +
' version...</a>')
document.write('<a href="/' + language.code +
'/index.html">Redirecting to the ' + language.name +
' version...</a>');
</script>
</body>
</html>

View File

@ -1,10 +0,0 @@
---
title: Thank You.
permalink: thank_you.html
layout: default
---
Thank you!
----------
Thank you for your feedback. We appreciate it.

View File

@ -1,30 +0,0 @@
import pandoc, sys
pandoc.PANDOC_PATH = '/usr/bin/pandoc'
if len(sys.argv) != 2:
sys.stderr.write("USAGE: to_mediawiki.py path/to/chapter.md")
sys.exit(-1)
sys.stderr.write("Reading from " + sys.argv[1] + "\n")
ifile = open(sys.argv[1])
input_t = ""
for line in ifile.readlines():
if len(line.strip()) > 0 and line.strip()[len(line.strip()) - 1] == "\\":
sys.stderr.write("found 1!\n")
line = line.strip("\n").strip("\\")
line += "<br />\n"
input_t += line
doc = pandoc.Document()
input_t = input_t.replace("{% highlight lua %}", "<pre>")
input_t = input_t.replace("{% endhighlight %}", "</pre>")
input_t = input_t.replace("{{ page.root }}/static/", "modding_book_")
input_t = input_t.replace("{{ page.root }}", "")
doc.markdown = input_t
sys.stdout.write("{{ ModdingBook }}\n\n")
sys.stdout.write(doc.mediawiki)