Rename section_config to language, update Activist
This commit is contained in:
parent
a0e85075ef
commit
6810d53a3e
5
.activist.yml
Normal file
5
.activist.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
languages:
|
||||||
|
- de
|
||||||
|
- it
|
||||||
|
- en
|
@ -1,4 +1,4 @@
|
|||||||
{% include section_config %}
|
{% include language %}
|
||||||
|
|
||||||
<h1 id="ukusa" class="anchor"><a href="#ukusa"><i class="fas fa-link anchor-icon"></i></a> {{ lang.title }} </h1>
|
<h1 id="ukusa" class="anchor"><a href="#ukusa"><i class="fas fa-link anchor-icon"></i></a> {{ lang.title }} </h1>
|
||||||
<img src="/assets/img/layout/UKUSA.png" class="img-fluid float-right" alt="UKUSA Agreement" style="margin-left:10px;">
|
<img src="/assets/img/layout/UKUSA.png" class="img-fluid float-right" alt="UKUSA Agreement" style="margin-left:10px;">
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% include section_config %}
|
{% include language %}
|
||||||
|
|
||||||
<h1 id="kdl" class="anchor"><a href="#kdl"><i class="fas fa-link anchor-icon"></i></a> {{ lang.title }}</h1>
|
<h1 id="kdl" class="anchor"><a href="#kdl"><i class="fas fa-link anchor-icon"></i></a> {{ lang.title }}</h1>
|
||||||
### {{ lang.subheading }}
|
### {{ lang.subheading }}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% include section_config %}
|
{% include language %}
|
||||||
|
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>{{ lang.title }}</h1>
|
<h1>{{ lang.title }}</h1>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{% include section_config %}
|
{% include language %}
|
||||||
|
|
||||||
<h3 id="usa" class="anchor">{{ lang.title }}</h3>
|
<h3 id="usa" class="anchor">{{ lang.title }}</h3>
|
||||||
|
|
||||||
|
32
activist.py
32
activist.py
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
from yaml import safe_load as yaml_safe_load
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A tool to make working with localized sections easier.
|
A tool to make working with localized sections easier.
|
||||||
@ -11,8 +12,7 @@ class Activist:
|
|||||||
def help(self):
|
def help(self):
|
||||||
print("""
|
print("""
|
||||||
Available commands:
|
Available commands:
|
||||||
make:section name Creates all files needed for a new section.
|
make:section name Creates all files needed for a new section.
|
||||||
make:strings name string [str2,str3,...] Adds a string to a langs/ file.
|
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def handle(self, args):
|
def handle(self, args):
|
||||||
@ -26,8 +26,7 @@ Available commands:
|
|||||||
|
|
||||||
def run(self, command, arguments):
|
def run(self, command, arguments):
|
||||||
commands = {
|
commands = {
|
||||||
"make:section": self.make_section,
|
"make:section": self.make_section
|
||||||
"make:strings": self.make_strings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if command not in commands:
|
if command not in commands:
|
||||||
@ -43,27 +42,20 @@ Available commands:
|
|||||||
exit("Please supply a section name.")
|
exit("Please supply a section name.")
|
||||||
|
|
||||||
# create files
|
# create files
|
||||||
with open("_data/lang/en/%s.yml" % name, 'w') as f:
|
with open("_data/lang/%s.yml" % name, 'w') as f:
|
||||||
f.write("---\n\n---")
|
f.write("---\n")
|
||||||
with open("_includes/langs/%s" % name, 'w'): pass
|
f.write("en: &base\n title: Section Title\n\n")
|
||||||
|
with open(".activist.yml", "r") as config:
|
||||||
|
# get list of languages except "en"
|
||||||
|
for language in filter(lambda lang: lang != "en", yaml_safe_load(config.read())['languages']):
|
||||||
|
f.write("{0}:\n <<: *base\n # title: Section Title in {0}\n\n".format(language))
|
||||||
|
f.write("---")
|
||||||
with open("_includes/content/%s.md" % name, 'w') as f:
|
with open("_includes/content/%s.md" % name, 'w') as f:
|
||||||
f.write("{% include section_config section=include.section lang=include.lang %}\n\n")
|
f.write("{% include language %}\n\n")
|
||||||
print("""Add this line to index.html:
|
print("""Add this line to index.html:
|
||||||
|
|
||||||
{% include section name=\""""+ name + """\" %}""")
|
{% include section name=\""""+ name + """\" %}""")
|
||||||
print("\nAnd don't forge to add the section to the navbar in _layouts/default.html!")
|
print("\nAnd don't forge to add the section to the navbar in _layouts/default.html!")
|
||||||
|
|
||||||
def make_strings(self, arguments):
|
|
||||||
try:
|
|
||||||
name, *strings = arguments
|
|
||||||
assert(len(strings) > 0)
|
|
||||||
except:
|
|
||||||
exit("Please supply the names of the strings that you wish to add.")
|
|
||||||
|
|
||||||
with open("_includes/langs/%s" % name, "a+") as f:
|
|
||||||
for string in strings:
|
|
||||||
f.write("{{% assign {0} = include.lang.{0} | default: include.en.{0} %}}\n"
|
|
||||||
.format(string))
|
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
Reference in New Issue
Block a user