scripts: import_translations: add shellscript that processes some Tusky translations to ours, replaces links, names. Add xq utility from https://github.com/jeffbr13/xq
parent
341c77ff37
commit
c860e9ae29
@ -0,0 +1,47 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
FIXUP_TUSKY="//string[@name='restart_emoji'] | \ |
||||||
|
//string[@name='about_tusky_version'] | \ |
||||||
|
//string[@name='about_powered_by_tusky'] | \ |
||||||
|
//string[@name='about_tusky_license'] | \ |
||||||
|
//string[@name='about_tusky_account'] | \ |
||||||
|
//string[@name='license_description']" |
||||||
|
FIXUP_WEBSITE="//string[@name='about_project_site']" |
||||||
|
FIXUP_BUGTRACKER="//string[@name='about_bug_feature_request_site']" |
||||||
|
FIXUP_MASTODON="//string[@name='action_login'] | \ |
||||||
|
//string[@name='add_account_description'] | \ |
||||||
|
//string[@name='warning_scheduling_interval']" |
||||||
|
FIXUP_INSTANCES="//string[@name='dialog_whats_an_instance']" |
||||||
|
|
||||||
|
SOURCE_ROOT=$PWD |
||||||
|
|
||||||
|
logue() { |
||||||
|
sed -E 's/(<.?result>|<.?results.?>)//g' |
||||||
|
} |
||||||
|
|
||||||
|
prologue() { |
||||||
|
logue | awk -v FS=$'\b' -v RS=$'\b' '{ print "<resources>"$1}' |
||||||
|
} |
||||||
|
|
||||||
|
epilogue() { |
||||||
|
logue | awk -v FS=$'\b' -v RS=$'\b' '{ print $1"</resources>"}' |
||||||
|
} |
||||||
|
|
||||||
|
pushd app/src/main/res/ |
||||||
|
for i in values*/strings.xml; |
||||||
|
do |
||||||
|
DIRECTORY=$(dirname $i) |
||||||
|
|
||||||
|
echo $DIRECTORY |
||||||
|
|
||||||
|
mkdir -p ../../husky/res/$DIRECTORY/ |
||||||
|
|
||||||
|
# add <resources>, some strings |
||||||
|
$SOURCE_ROOT/scripts/xq.py "$FIXUP_TUSKY" $i | prologue | sed -E 's|Tusky|Husky|g' > ../../husky/res/$DIRECTORY/husky_generated.xml |
||||||
|
$SOURCE_ROOT/scripts/xq.py "$FIXUP_WEBSITE" $i | logue | sed -E 's|https://tusky.app|https://husky.fwgs.ru|g' >> ../../husky/res/$DIRECTORY/husky_generated.xml |
||||||
|
$SOURCE_ROOT/scripts/xq.py "$FIXUP_BUGTRACKER" $i | logue | sed -E 's|https://github.com/tuskyapp/Tusky/issues|https://git.mentality.rip/FWGS/Husky/issues|g' >> ../../husky/res/$DIRECTORY/husky_generated.xml |
||||||
|
$SOURCE_ROOT/scripts/xq.py "$FIXUP_MASTODON" $i | logue | sed -E 's|Mastodon|Pleroma|g' >> ../../husky/res/$DIRECTORY/husky_generated.xml |
||||||
|
$SOURCE_ROOT/scripts/xq.py "$FIXUP_INSTANCES" $i | epilogue | sed -E 's|mastodon.social|shitposter.club|g' | sed -E 's|icosahedron.website|blob.cat|g' | sed -E 's|social.tchncs.de|expired.mentality.rip|g' | sed -E 's|https://instances.social|https://fediverse.network/pleroma?count=peers|g' >> ../../husky/res/$DIRECTORY/husky_generated.xml |
||||||
|
|
||||||
|
done |
||||||
|
popd |
@ -0,0 +1,65 @@ |
|||||||
|
#!/usr/bin/env python3 |
||||||
|
|
||||||
|
# Based on jeffbr's xq |
||||||
|
# a1ba: added unicode output |
||||||
|
|
||||||
|
import argparse |
||||||
|
import sys |
||||||
|
from typing import Union |
||||||
|
|
||||||
|
from lxml import etree |
||||||
|
from lxml.builder import E |
||||||
|
from pygments import highlight |
||||||
|
from pygments.formatters.other import NullFormatter |
||||||
|
from pygments.formatters.terminal import TerminalFormatter |
||||||
|
from pygments.lexers.html import XmlLexer |
||||||
|
|
||||||
|
# from . import NAME, DESCRIPTION, VERSION |
||||||
|
NAME = 'xq' |
||||||
|
VERSION = '0.0.4' |
||||||
|
DESCRIPTION = 'like jq but for XML and XPath' |
||||||
|
|
||||||
|
def wrap_in_results(elements: [Union[etree._Element, etree._ElementUnicodeResult]]) -> etree._Element: |
||||||
|
results = E.results() |
||||||
|
for el in elements: |
||||||
|
results.append(E.result(el)) |
||||||
|
return results |
||||||
|
|
||||||
|
|
||||||
|
def apply_xpath(infile, xpath_query=None, colorize=False): |
||||||
|
try: |
||||||
|
parsed = etree.parse(infile, etree.XMLParser(remove_blank_text=True)) |
||||||
|
except etree.XMLSyntaxError: |
||||||
|
parsed = etree.parse(infile, etree.HTMLParser(remove_blank_text=True)) |
||||||
|
|
||||||
|
if xpath_query: |
||||||
|
matches = parsed.xpath(xpath_query) |
||||||
|
results = wrap_in_results(matches) |
||||||
|
output = etree.tostring(results, pretty_print=True, encoding='unicode') |
||||||
|
else: |
||||||
|
output = etree.tostring(parsed, pretty_print=True, encoding='unicode') |
||||||
|
|
||||||
|
formatter = TerminalFormatter() if colorize else NullFormatter() |
||||||
|
return highlight(output, XmlLexer(), formatter) |
||||||
|
|
||||||
|
|
||||||
|
def main(): |
||||||
|
parser = argparse.ArgumentParser( |
||||||
|
prog=NAME, |
||||||
|
description=DESCRIPTION, |
||||||
|
) |
||||||
|
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + VERSION) |
||||||
|
parser.add_argument( |
||||||
|
'xpath_query', nargs='?', type=str, |
||||||
|
help='XPath query to apply to XML document.' |
||||||
|
) |
||||||
|
parser.add_argument( |
||||||
|
'file', nargs='?', type=argparse.FileType('r'), default=sys.stdin, |
||||||
|
help='XML file to process. Defaults to STDIN.', |
||||||
|
) |
||||||
|
args = parser.parse_args() |
||||||
|
sys.stdout.write(apply_xpath(args.file, args.xpath_query, sys.stdout.isatty())) |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': |
||||||
|
main() |
Loading…
Reference in new issue