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
* _data/ - Contains the navigation bar file.
* `_data/` - Contains the navigation bar file.
(a list of links and link text for the navbar.)
* _includes/ - Contains HTML templates.
* _layouts/ - You can safely ignore this.
* static/ - CSS, images, scripts.
* chapters/ - Markdown files for each chapter.
* `_includes/` - Contains HTML templates.
* `_layouts/` - You can safely ignore this.
* `static/` - CSS, images, scripts.
* `<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

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
- hr: true
- title: Lua Modding API Reference
link: lua_api.html

View File

@ -9,20 +9,34 @@
<meta name="author" content="rubenwardy">
</head>
<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">
{% for link in site.data.links %}
{% if link.hr %}
{% assign hr = true %}
{% else %}
<li><a href="{{ page.root }}{{ link.link }}"
class="{% if page.title == link.title %}selected{% endif %}{% if hr %} hr {% endif %}">
{% if link.num %} {{ link.num }} - {% endif %}
{{ link.title }}</a></li>
{% assign hr = false %}
{% endif %}
{% for link in links %}
{% if link.hr %}
{% assign hr = true %}
{% else %}
<li><a href="{{ page.root }}{{ language }}/{{ link.link }}"
class="{% if page.title == link.title %}selected{% endif %}{% if hr %} hr {% endif %}">
{% if link.num %} {{ link.num }} - {% endif %}
{{ link.title }}</a></li>
{% assign hr = false %}
{% endif %}
{% 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 id="printable">Printable Version</a></li>
</ul>
<div id="page">
<h1>{{ page.title }}</h1>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,14 +1,14 @@
---
title: Introduction
permalink: index.html
layout: default
root: ../
---
Welcome
-------
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.
### 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)