1#!/bin/sh
2if [ -z "$1" ]; then
3	echo "Usage:"
4	echo " sys/translate.sh [--options] [lang|path]"
5	echo "Options:"
6	echo " --list       list all supported languages"
7	echo " --update     update from radare2-translations git"
8	echo " --reset      restore default strings"
9	echo "Languages:"
10	echo " - english"
11	if [ -d "sys/lang" ]; then
12		cd sys/lang && ls | xargs echo ' -'
13	else
14		echo "Run --update for more languages"
15	fi
16	exit 1
17fi
18
19if [ "$1" = "--update" ]; then
20	if [ -d "sys/lang" ]; then
21		( cd sys/lang && git pull )
22	else
23		git clone --depth 1 https://github.com/radare/radare2-translations sys/lang || exit 1
24	fi
25	exit 0
26fi
27
28if [ "$1" = "-l" -o "$1" = "--list" ]; then
29	echo english
30	cd sys/lang && ls | cat
31	exit 0
32fi
33
34if [ "$1" = english ]; then
35	RESET=1
36	N=catalan
37else
38	if [ "$1" = "--reset" ]; then
39		RESET=1
40		shift
41	else
42		RESET=0
43	fi
44	N="$1"
45fi
46
47if [ -d "$N" ]; then
48	:
49else
50	if [ -d "sys/lang/$N" ]; then
51		L="sys/lang/$N"
52	else
53		if [ -d "$N" ]; then
54			L="$N"
55		else
56			echo "Invalid language"
57			exit 1
58		fi
59	fi
60fi
61
62echo
63echo "WARNING: Translations are experimental and can only be changed at compile time"
64echo "WARNING: Everyone is welcome to submit their translation efforts. I have no plans"
65echo "WARNING: to support runtime language selection, because of the unnecessary overhead"
66echo
67
68for a in `cd "$L" && echo *` ; do
69	F=`echo $a | sed -e s,_,/,g`
70	echo "Processing $F"
71	git checkout "$F"
72	if [ "${RESET}" = 0 ]; then
73		sed -f "$L/$a" < "$F" > .tmp
74		if [ $? = 0 ]; then
75			mv .tmp $F
76		else
77			echo "Failed"
78		fi
79	fi
80done
81