Add the hint-files synchronization with Transifex.
[midnight-commander.git] / maint / sync-transifex / functions
blob7cdf5a09bc73362c5aea8d17e72b8f13ca6ac006
1 #!/bin/bash
3 # Midnight Commander - common functions for playing with translations.
5 # Copyright (C) 2013
6 # The Free Software Foundation, Inc.
8 # Written by:
9 # Slava Zanko <slavazanko@gmail.com>, 2013
11 # This file is part of the Midnight Commander.
13 # The Midnight Commander is free software: you can redistribute it
14 # and/or modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation, either version 3 of the License,
16 # or (at your option) any later version.
18 # The Midnight Commander is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #*** include section (source functions, for example) *******************
28 #*** file scope functions **********************************************
29 # ----------------------------------------------------------------------
31 ## Returns name of working directory.
33 ## @param sync_file_name file name which will be sync'ed with Transifex
34 ## @return name of working directory
36 getSyncDirName() {
37 sync_file_name=$1; shift
38 echo "${SYNC_TX_CURRENT_DIR}/var.d/${sync_file_name}"
41 # ----------------------------------------------------------------------
43 ## Returns config file name as full path.
45 ## @param sync_file_name file name which will be sync'ed with Transifex
46 ## @param config_file_name config file name
47 ## @return config file name
49 getConfigFile() {
50 sync_file_name=$1; shift
51 config_file_name=$1; shift
53 echo "${MC_SOURCE_ROOT_DIR}/maint/sync-transifex/config.d/${sync_file_name}/${config_file_name}"
56 # ----------------------------------------------------------------------
59 ## Returns name of working directory. Init the directory, if needed.
61 ## @param sync_file_name file name which will be sync'ed with Transifex
62 ## @return name of working directory
64 initSyncDirIfNeeded() {
65 sync_file_name=$1; shift
67 sync_dir_name=$(getSyncDirName "${sync_file_name}")
69 [ ! -e "${sync_dir_name}" ] && mkdir -p "${sync_dir_name}/.tx"
70 cp \
71 "$(getConfigFile ${sync_file_name} 'tx.config')" \
72 "${sync_dir_name}/.tx/config"
74 echo "${sync_dir_name}"
77 # ----------------------------------------------------------------------
79 ## Convert file from plain text to POT-file format.
81 ## @param source_file path to plain text file
82 ## @param destination_file path to po-file
84 convertFromTextToPo() {
85 source_file=$1; shift
86 destination_file=$1; shift
88 po4a-gettextize -f text -m "${source_file}" -p "${destination_file}"
91 # ----------------------------------------------------------------------
93 ## Send POT-file to Transifex.
95 ## @param tx_work_dir working directory where placed the POT file and
96 ## a config-file for tx utility
98 sendSourceToTransifex() {
99 tx_work_dir=$1; shift
101 tx -r "${tx_work_dir}" push -s
104 # ----------------------------------------------------------------------
106 ## Reveive translations from Transifex.
108 ## @param tx_work_dir working directory where placed the POT file and
109 ## a config-file for tx utility
111 receiveTranslationsFromTransifex() {
112 tx_work_dir=$1; shift
114 pushd "${tx_work_dir}" >/dev/null
115 tx pull --all --force
116 popd >/dev/null
119 # ----------------------------------------------------------------------
121 ## Create po4a.cfg file.
123 ## @param sync_file_name file name which will be sync'ed with Transifex
125 createPo4A() {
126 sync_file_name=$1; shift
128 sync_dir_name=$(getSyncDirName "${sync_file_name}")
129 [ ! -e "${sync_dir_name}" ] && mkdir -p "${sync_dir_name}"
131 pushd $sync_dir_name >/dev/null
132 translations=$(ls *.po| sed -e 's/.po//g'| tr '\n' ' ')
133 popd >/dev/null
134 sed -e 's!@srcdir@!'"${MC_SOURCE_ROOT_DIR}"'!g' \
135 -e 's!@translations@!'"${translations}"'!g' \
136 "$(getConfigFile ${sync_file_name} 'po4a.cfg')" \
137 > "${sync_dir_name}/po4a.cfg"
140 # ----------------------------------------------------------------------
142 ## Create po4a.cfg file.
144 ## @param sync_dir_name working directory where placed translations
145 ## @param sync_file_name file name which will be sync'ed with Transifex
147 convertFromPoToText() {
148 sync_dir_name=$1; shift
149 sync_file_name=$1; shift
151 po4a -k 0 -q \
152 -M UTF-8 -L UTF-8 \
153 --variable docfile="${sync_file_name}" \
154 "${sync_dir_name}/po4a.cfg"
157 # ----------------------------------------------------------------------
158 #*** main code *********************************************************
160 SYNC_TX_CURRENT_DIR=${SYNC_TX_CURRENT_DIR:-$(pwd)}