Commit 50bdae7c authored by Yuri Chornoivan's avatar Yuri Chornoivan
Browse files

Fix Step infobrowser and examples localization

Summary: Currently (version 19.12), all object info and examples localizations are useless. This patch fixes current way of extracting and using Step translations.

Test Plan:
1. Extraction works. However, I'm uncertain if it is worth to have separate catalogs for object infos and examples (please, give an advice).

2. Translation (when put into the common /po dir) compiles and works. Translations are installed into the objinfo/<locale> dir to avoid conflicts with current lag packs. It is tested that Step can display the compiled localized HTML files.

Screenshot with translated tutorial and infobrowser (Ukrainian, clean install):
{F7773066}

Reviewers: #kde_edu, #localization, cordlandwehr

Reviewed By: cordlandwehr

Subscribers: ltoscano, pino, aacid, cordlandwehr, kde-edu

Tags: #kde_edu

Differential Revision: https://phabricator.kde.org/D25405
parent 9954dc42
......@@ -60,7 +60,6 @@ if(STEP_WITH_QALCULATE)
add_definitions (-fexceptions)
endif(STEP_WITH_QALCULATE)
qt5_add_resources(step_SRCS data/resources.qrc)
ki18n_wrap_ui(step_SRCS ${step_UIS})
kconfig_add_kcfg_files(step_SRCS ${step_KCFGS})
......
if(CURRENT_LANG)
set(STEP_BUILD_TRANSLATIONS 1)
endif(CURRENT_LANG)
find_package(PythonInterp)
set(EXTRACTXML_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/extractxml)
if(STEP_BUILD_TRANSLATIONS)
if(PYTHON_EXECUTABLE)
find_package(PythonInterp)
set(EXTRACTXML_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/extractxml)
# STEP_PROCESS_XML_TRANSLATION(<lang> <extractxml_args> [ALL] [INSTALL_DESTINATION <dir>] <xml1> <xml2> ...)
macro(STEP_PROCESS_XML_TRANSLATION _lang _po_file _extractxml_args)
set(_xmlfiles_tr)
set(_args ${ARGN})
set(_addToAll)
set(_installDest)
if(PYTHON_EXECUTABLE)
list(GET _args 0 _tmp)
if("${_tmp}" STREQUAL "ALL")
set(_addToAll ALL)
list(REMOVE_AT _args 0)
endif("${_tmp}" STREQUAL "ALL")
# STEP_PROCESS_XML_TRANSLATION(<lang> <extractxml_args> [ALL] [INSTALL_DESTINATION <dir>] <xml1> <xml2> ...)
macro(STEP_PROCESS_XML_TRANSLATION _lang _po_file _extractxml_args)
set(_xmlfiles_tr)
set(_args ${ARGN})
set(_addToAll)
set(_installDest)
list(GET _args 0 _tmp)
if("${_tmp}" STREQUAL "INSTALL_DESTINATION")
list(GET _args 1 _installDest )
list(REMOVE_AT _args 0 1)
endif("${_tmp}" STREQUAL "INSTALL_DESTINATION")
list(GET _args 0 _tmp)
if("${_tmp}" STREQUAL "ALL")
set(_addToAll ALL)
list(REMOVE_AT _args 0)
endif("${_tmp}" STREQUAL "ALL")
if(EXISTS ${_po_file})
get_filename_component(_po_file_we ${_po_file} NAME_WE)
set(_mo_file ${CMAKE_CURRENT_BINARY_DIR}/${_po_file_we}.mo)
add_custom_command(OUTPUT ${_mo_file}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_mo_file} ${_po_file}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS ${_po_file}
)
list(GET _args 0 _tmp)
if("${_tmp}" STREQUAL "INSTALL_DESTINATION")
list(GET _args 1 _installDest )
list(REMOVE_AT _args 0 1)
endif("${_tmp}" STREQUAL "INSTALL_DESTINATION")
foreach(_xmlfile ${_args})
get_filename_component(_xmlfile_basename ${_xmlfile} NAME)
set(_xmlfile_tr ${CMAKE_CURRENT_BINARY_DIR}/${_xmlfile_basename})
set(_extractxml_args_copy ${_extractxml_args})
separate_arguments(_extractxml_args_copy)
add_custom_command(OUTPUT ${_xmlfile_tr}
COMMAND ${EXTRACTXML_EXECUTABLE} --translate --mo-file=${_mo_file} --output-dir=${CMAKE_CURRENT_BINARY_DIR} ${_extractxml_args_copy} ${_xmlfile}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS ${_xmlfile} ${_mo_file}
)
if(_installDest)
install(FILES ${_xmlfile_tr} DESTINATION ${_installDest}/${_lang})
endif(_installDest)
list(APPEND _xmlfiles_tr ${_xmlfile_tr})
endforeach(_xmlfile)
if(EXISTS ${_po_file})
get_filename_component(_po_file_we ${_po_file} NAME_WE)
set(_mo_file ${CMAKE_CURRENT_BINARY_DIR}/${_po_file_we}.mo)
add_custom_command(OUTPUT ${_mo_file}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_mo_file} ${_po_file}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS ${_po_file}
)
get_filename_component(DirId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
add_custom_target(${DirId}_${_po_file_we}_xmlfiles_tr ${_addToAll} DEPENDS ${_xmlfiles_tr})
endif(EXISTS ${_po_file})
endmacro(STEP_PROCESS_XML_TRANSLATION)
foreach(_xmlfile ${_args})
get_filename_component(_xmlfile_basename ${_xmlfile} NAME)
set(_xmlfile_tr ${CMAKE_CURRENT_BINARY_DIR}/${_xmlfile_basename})
set(_extractxml_args_copy ${_extractxml_args})
separate_arguments(_extractxml_args_copy)
add_custom_command(OUTPUT ${_xmlfile_tr}
COMMAND ${EXTRACTXML_EXECUTABLE} --translate --mo-file=${_mo_file} --output-dir=${CMAKE_CURRENT_BINARY_DIR} ${_extractxml_args_copy} ${_xmlfile}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS ${_xmlfile} ${_mo_file}
)
if(_installDest)
install(FILES ${_xmlfile_tr} DESTINATION ${_installDest}/${_lang})
endif(_installDest)
list(APPEND _xmlfiles_tr ${_xmlfile_tr})
endforeach(_xmlfile)
add_custom_target(xmlfiles_tr ${_addToAll} DEPENDS ${_xmlfiles_tr})
endif(EXISTS ${_po_file})
endmacro(STEP_PROCESS_XML_TRANSLATION)
else(PYTHON_EXECUTABLE)
message("Python executable NOT found - Step data translations will not be build")
macro(STEP_PROCESS_XML_TRANSLATION)
endmacro(STEP_PROCESS_XML_TRANSLATION)
endif(PYTHON_EXECUTABLE)
endif(STEP_BUILD_TRANSLATIONS)
else(PYTHON_EXECUTABLE)
message("Python executable NOT found - Step data translations will not be build")
macro(STEP_PROCESS_XML_TRANSLATION)
endmacro(STEP_PROCESS_XML_TRANSLATION)
endif(PYTHON_EXECUTABLE)
add_subdirectory(objectinfo)
add_subdirectory(examples)
......
......@@ -10,9 +10,8 @@ $EXTRACTXML --extract \
--parse-unquoted='--context=HTML:%(tag)s --tag-regex=^(?:title|body|p|h[1-6])$ --recursive --strip' \
./examples/*.step ./tutorials/*.step --output=examples.cpp
# Temporary commented-out
#$XGETTEXT objinfo.cpp -o $podir/step_objinfo_files.pot
#$XGETTEXT examples.cpp -o $podir/step_example_files.pot
$XGETTEXT objinfo.cpp -o $podir/step_objinfo_files.pot
$XGETTEXT examples.cpp -o $podir/step_example_files.pot
rm -f objinfo.cpp
rm -f examples.cpp
......
FILE(GLOB STEP_EXAMPLE_FILES "*.step")
if(STEP_BUILD_TRANSLATIONS)
set(po_file ${CMAKE_SOURCE_DIR}/messages/kdeedu/step_example_files.po)
STEP_PROCESS_XML_TRANSLATION(${CURRENT_LANG} ${po_file}
"--context='%(tag)s' --tag=name --tag=text --unquote --parse-unquoted='--context=HTML:%(tag)s --tag-regex=^(?:title|body|p|h[1-6])$$ --recursive --strip'"
ALL INSTALL_DESTINATION ${KDE_INSTALL_DATADIR}/step/examples
${STEP_EXAMPLE_FILES})
else(STEP_BUILD_TRANSLATIONS)
install(FILES
install(FILES
${STEP_EXAMPLE_FILES}
DESTINATION ${KDE_INSTALL_DATADIR}/step/examples)
endif(STEP_BUILD_TRANSLATIONS)
FILE(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*/step_example_files.po")
foreach(po_file ${po_files})
get_filename_component(po_dir ${po_file} DIRECTORY)
get_filename_component(CURRENT_LANG ${po_dir} NAME)
STEP_PROCESS_XML_TRANSLATION(${CURRENT_LANG} ${po_file}
"--context='%(tag)s' --tag=name --tag=text --unquote --parse-unquoted='--context=HTML:%(tag)s --tag-regex=^(?:title|body|p|h[1-6])$$ --recursive --strip'"
ALL INSTALL_DESTINATION ${KDE_INSTALL_DATADIR}/step/examples
${STEP_EXAMPLE_FILES})
endforeach()
FILE(GLOB INFO_HTML_FILES "*.html")
if(STEP_BUILD_TRANSLATIONS)
install(FILES
${INFO_HTML_FILES}
DESTINATION ${KDE_INSTALL_DATADIR}/step/objinfo)
set(po_file ${CMAKE_SOURCE_DIR}/messages/kdeedu/step_objinfo_files.po)
FILE(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*/step_objinfo_files.po")
foreach(po_file ${po_files})
get_filename_component(po_dir ${po_file} DIRECTORY)
get_filename_component(CURRENT_LANG ${po_dir} NAME)
STEP_PROCESS_XML_TRANSLATION(${CURRENT_LANG} ${po_file}
"--context='%(filename)s:%(tag)s' --tag-regex='^(?:title|body|p|h[1-6])$$' --recursive --strip"
ALL INSTALL_DESTINATION ${KDE_INSTALL_DATADIR}/step/objinfo
${INFO_HTML_FILES})
endif(STEP_BUILD_TRANSLATIONS)
"--context='%(filename)s:%(tag)s' --tag-regex='^(?:title|body|p|h[1-6])$$' --recursive --strip"
ALL INSTALL_DESTINATION ${KDE_INSTALL_DATADIR}/step/objinfo/l10n
${INFO_HTML_FILES})
endforeach()
<RCC>
<qresource>
<file>objectinfo/anchor.html</file>
<file>objectinfo/box.html</file>
<file>objectinfo/chargedparticle.html</file>
<file>objectinfo/coulombforce.html</file>
<file>objectinfo/disk.html</file>
<file>objectinfo/gas.html</file>
<file>objectinfo/gasljforce.html</file>
<file>objectinfo/gasparticle.html</file>
<file>objectinfo/gravitationforce.html</file>
<file>objectinfo/linearmotor.html</file>
<file>objectinfo/meter.html</file>
<file>objectinfo/note.html</file>
<file>objectinfo/particle.html</file>
<file>objectinfo/pin.html</file>
<file>objectinfo/polygon.html</file>
<file>objectinfo/softbody.html</file>
<file>objectinfo/spring.html</file>
<file>objectinfo/weightforce.html</file>
<file>objectinfo/world.html</file>
</qresource>
</RCC>
FILE(GLOB STEP_TUTORIALS_FILES "*.step")
if(STEP_BUILD_TRANSLATIONS)
set(po_file ${CMAKE_SOURCE_DIR}/messages/kdeedu/step_example_files.po)
STEP_PROCESS_XML_TRANSLATION(${CURRENT_LANG} ${po_file}
"--context='%(tag)s' --tag=name --tag=text --unquote --parse-unquoted='--context=HTML:%(tag)s --tag-regex=^(?:title|body|p|h[1-6])$$ --recursive --strip'"
ALL INSTALL_DESTINATION ${KDE_INSTALL_DATADIR}/step/tutorials
${STEP_TUTORIALS_FILES})
else(STEP_BUILD_TRANSLATIONS)
install(FILES
install(FILES
${STEP_TUTORIALS_FILES}
DESTINATION ${KDE_INSTALL_DATADIR}/step/tutorials)
endif(STEP_BUILD_TRANSLATIONS)
FILE(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*/step_example_files.po")
foreach(po_file ${po_files})
get_filename_component(po_dir ${po_file} DIRECTORY)
get_filename_component(CURRENT_LANG ${po_dir} NAME)
STEP_PROCESS_XML_TRANSLATION(${CURRENT_LANG} ${po_file}
"--context='%(tag)s' --tag=name --tag=text --unquote --parse-unquoted='--context=HTML:%(tag)s --tag-regex=^(?:title|body|p|h[1-6])$$ --recursive --strip'"
ALL INSTALL_DESTINATION ${KDE_INSTALL_DATADIR}/step/tutorials
${STEP_TUTORIALS_FILES})
endforeach()
......@@ -153,7 +153,7 @@ void InfoBrowser::openUrl(const QUrl& url, bool clearHistory, bool fromHistory)
"</body></html>", fromHistory, url );
return;
}
QString fileName = QStringLiteral(":/objectinfo/%1.html").arg(className.toLower());
QString fileName = KLocalizedString::localizedFilePath(QStandardPaths::locate(QStandardPaths::DataLocation, QStringLiteral("objinfo/%1.html").arg(className.toLower())));
if(!fileName.isEmpty()) {
QFile file(fileName);
if(file.open(QIODevice::ReadOnly | QIODevice::Text)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment