mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-10-06 09:17:07 +02:00
Remove update translations from CMake to python script
This commit is contained in:
parent
83bb652132
commit
17347f324e
@ -3,8 +3,7 @@ project(CMake)
|
||||
set(FILES
|
||||
CopyRecursive.cmake
|
||||
CreateIFWInstaller.cmake
|
||||
FetchContentThirdParty.cmake
|
||||
QtUpdateTranslations.cmake)
|
||||
FetchContentThirdParty.cmake)
|
||||
|
||||
add_custom_target(
|
||||
${PROJECT_NAME}
|
||||
|
@ -1,16 +0,0 @@
|
||||
find_program(LUPDATE_EXECUTABLE lupdate)
|
||||
find_program(LRELEASE_EXECUTABLE lrelease)
|
||||
|
||||
# Updates all ts files and generates .qm
|
||||
# Absolute paths are needed!
|
||||
# qt_update_translations("${CMAKE_CURRENT_SOURCE_DIR}/qml" "${L10N_LIST}")
|
||||
# The second argument (list) __must__ be passed as string!
|
||||
function(qt_update_translations SOURCE_PATH TS_FILES)
|
||||
|
||||
foreach(_ts_file ${TS_FILES})
|
||||
message(STATUS "Update Translation: ${_ts_file}")
|
||||
execute_process(COMMAND ${LUPDATE_EXECUTABLE} -noobsolete -locations none -recursive ${SOURCE_PATH} -ts ${_ts_file} OUTPUT_QUIET)
|
||||
execute_process(COMMAND ${LRELEASE_EXECUTABLE} ${_ts_file} OUTPUT_QUIET)
|
||||
endforeach()
|
||||
|
||||
endfunction()
|
@ -323,14 +323,6 @@ else()
|
||||
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/translations")
|
||||
endif()
|
||||
|
||||
# qt_add_lupdate does not work for some reason. Lets do it manually:
|
||||
find_program(LUPDATE_EXECUTABLE lupdate)
|
||||
foreach(_ts_file ${TS_FILES})
|
||||
message(STATUS "Update Translation: ${_ts_file}")
|
||||
execute_process(COMMAND ${LUPDATE_EXECUTABLE} -noobsolete -locations none -recursive ${CMAKE_CURRENT_SOURCE_DIR}/qml -ts
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${_ts_file} OUTPUT_QUIET)
|
||||
endforeach()
|
||||
|
||||
qt_add_lrelease(${PROJECT_NAME} TS_FILES ${TS_FILES})
|
||||
|
||||
target_include_directories(
|
||||
|
49
Tools/update_translations.py
Normal file
49
Tools/update_translations.py
Normal file
@ -0,0 +1,49 @@
|
||||
import os
|
||||
import util
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import defines
|
||||
from execute_util import execute
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
|
||||
|
||||
def search_translations(root_dir):
|
||||
translations_files = []
|
||||
for dirpath, dirnames, filenames in os.walk(root_dir):
|
||||
if "translations" in dirnames:
|
||||
translations_dir = os.path.join(dirpath, "translations")
|
||||
for file in os.listdir(translations_dir):
|
||||
if file.endswith(".ts"):
|
||||
translations_files.append(
|
||||
os.path.join(translations_dir, file))
|
||||
return translations_files
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
translations = search_translations(os.path.join(util.repo_root_path(), ""))
|
||||
|
||||
if translations:
|
||||
print("Found translations:")
|
||||
for translation in translations:
|
||||
print(translation)
|
||||
else:
|
||||
print("No translations found.")
|
||||
|
||||
executable = "lupdate"
|
||||
if os.name == 'nt':
|
||||
executable = "lupdate.exe"
|
||||
qt_bin_path = defines.QT_BIN_PATH
|
||||
executable = os.path.join(qt_bin_path, executable)
|
||||
|
||||
for translation in translations:
|
||||
ts = Path(translation)
|
||||
source_path = ts.parent.parent.resolve()
|
||||
print(f"LUpdate: {translation}. Using source: {source_path}")
|
||||
execute( command=f"{executable} -noobsolete -locations none -recursive {source_path} -ts {translation}",
|
||||
workingDir=ts.parent.resolve(),)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -31,6 +31,11 @@ def run_and_capture_output(cmd, cwd=Path.cwd()) -> str:
|
||||
if result.stdout is not None:
|
||||
return str(result.stdout.decode('utf-8'))
|
||||
return ""
|
||||
|
||||
def repo_root_path() -> str:
|
||||
# Root dir of the repository
|
||||
path = os.path.join(os.path.realpath(__file__), "../../")
|
||||
return os.path.realpath(path)
|
||||
|
||||
def cd_repo_root_path() -> str:
|
||||
# Make sure the script is always started from the same
|
||||
|
Loading…
Reference in New Issue
Block a user