2020-03-19 17:49:27 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Usage: translate.sh <target_language> <input> <output>
|
|
|
|
set -e
|
|
|
|
BASE_DIR=$(dirname $(readlink -f $0))
|
|
|
|
OUTPUT=${3:-/dev/stdout}
|
|
|
|
export TARGET_LANGUAGE="$1"
|
|
|
|
export DEBUG
|
|
|
|
TEMP_FILE=$(mktemp)
|
2020-04-03 13:23:32 +00:00
|
|
|
export INPUT_PATH="$2"
|
|
|
|
INPUT_META="${INPUT_PATH}.meta"
|
|
|
|
INPUT_CONTENT="${INPUT_PATH}.content"
|
|
|
|
|
|
|
|
trap 'rm -f -- "${TEMP_FILE}" "${INPUT_META}" "${INPUT_CONTENT}"' INT TERM HUP EXIT
|
2020-03-19 17:49:27 +00:00
|
|
|
source "${BASE_DIR}/venv/bin/activate"
|
2020-04-03 13:23:32 +00:00
|
|
|
|
|
|
|
${BASE_DIR}/split_meta.py "${INPUT_PATH}"
|
|
|
|
|
|
|
|
pandoc "${INPUT_CONTENT}" --filter "${BASE_DIR}/filter.py" -o "${TEMP_FILE}" \
|
2020-06-24 12:59:19 +00:00
|
|
|
-f "markdown-space_in_atx_header" -t "markdown_strict+pipe_tables+markdown_attribute+all_symbols_escapable+backtick_code_blocks+autolink_bare_uris-link_attributes+markdown_attribute+mmd_link_attributes-raw_attribute+header_attributes-grid_tables+definition_lists" \
|
2020-03-21 04:11:51 +00:00
|
|
|
--atx-headers --wrap=none --columns=99999 --tab-stop=4
|
2020-03-19 17:49:27 +00:00
|
|
|
perl -pi -e 's/{\\#\\#/{##/g' "${TEMP_FILE}"
|
|
|
|
perl -pi -e 's/\\#\\#}/##}/g' "${TEMP_FILE}"
|
2020-03-20 10:10:48 +00:00
|
|
|
perl -pi -e 's/ *$//gg' "${TEMP_FILE}"
|
2020-03-21 04:11:51 +00:00
|
|
|
if [[ "${TARGET_LANGUAGE}" == "ru" ]]
|
2020-03-20 18:20:59 +00:00
|
|
|
then
|
|
|
|
perl -pi -e 's/“/«/gg' "${TEMP_FILE}"
|
|
|
|
perl -pi -e 's/”/»/gg' "${TEMP_FILE}"
|
|
|
|
fi
|
2020-04-03 13:23:32 +00:00
|
|
|
cat "${INPUT_META}" "${TEMP_FILE}" > "${OUTPUT}"
|