Commit f4887b2d authored by Carl Schwan's avatar Carl Schwan

Merge branch 'translations' into 'master'

Add a script to extract/merge translations

See merge request !6
parents fb20db70 39eb11b9
......@@ -26,6 +26,15 @@ pygmentsCodefencesGuessSyntax = true
# add info for crawlers
enableRobotsTXT = true
# Add language that are translated here
[languages]
[languages.en]
weight = 1
# [languages.fr]
# weight = 2
# [languages.de]
# weight = 2
# default author
[Author]
name = "The Kate Team"
......
import click
import os
import subprocess
@click.group()
@click.pass_context
def cli(ctx: dict):
ctx.ensure_object(dict)
def webpage_list():
"""
Generate a list of webpage that need to be translated
"""
return ['content/about-kate.md']
@cli.command()
@click.argument("directory")
def extract(directory):
"""
First parameter will be the path of the directory where we have to store the pot files
"""
webpages = ""
for webpage in webpage_list():
webpages += " --master \"" + webpage + "\""
command = "po4a-gettextize --format asciidoc " + webpages + " --master-charset \"UTF-8\" --po \"" + directory + "\"/kate-editor-org.pot"
subprocess.run(command, shell=True, check=True, text=True)
@cli.command()
@click.argument("directory")
def import_po(directory):
"""
First parameter will be a path that will be a directory to the dirs for each lang and then all the .po files inside
"""
for translation in os.listdir(directory):
transdir = directory + "/" + translation
for po in os.listdir(transdir):
os.rename(directory + "/" + translation + "/" + po, "locale/" + translation + "/LC_MESSAGES/" + po)
@cli.command()
def generate_translations():
"""
Assume translation located at `translations/`
"""
for translations in os.listdir('locale'):
for webpage in webpage_list():
extension = os.path.splitext(webpage)[1]
basename = os.path.splitext(webpage)[0]
translated = basename + "." + translations + extension
print(translated)
command = "po4a-translate --format asciidoc --po \"locale/" + translations + "/LC_MESSAGES/kate-editor-org.po\" --master \"" + webpage + "\" --localized \"" + translated + "\" --master-charset \"UTF-8\""
subprocess.run(command, shell=True, check=True, text=True)
if __name__ == "__main__":
cli(obj={})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment