Skip to content

Commit

Permalink
Load and use stellarium-sky translations in addition to stellarium-sk…
Browse files Browse the repository at this point in the history
…ycultures
  • Loading branch information
10110111 committed Mar 8, 2024
1 parent bc078b1 commit 2e7402e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions po/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )


ADD_SUBDIRECTORY(stellarium)
ADD_SUBDIRECTORY(stellarium-sky)
ADD_SUBDIRECTORY(stellarium-skycultures)
ADD_SUBDIRECTORY(stellarium-planetary-features)
IF(ENABLE_SCRIPTING)
Expand Down
33 changes: 32 additions & 1 deletion po/stellarium-skycultures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,35 @@ FILE(GLOB poscfiles RELATIVE "${CMAKE_SOURCE_DIR}/po/stellarium-skycultures/" "*
LIST(SORT poscfiles)
STRING(REGEX REPLACE ".po" "" outposcfiles "${poscfiles}")

GETTEXT_CREATE_TRANSLATIONS(stellarium-skycultures DEFAULT_TARGET ${outposcfiles})
# This is a copy of the implementation of GETTEXT_CREATE_TRANSLATIONS, but
# without updating the .po or .pot files, because they are made by an external
# script from a separate repository.
set(_domain stellarium-skycultures)

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/translations/${_domain})

SET(_gmoFiles)

SET(_addToAll "ALL")

FOREACH (_lang ${outposcfiles})
GET_FILENAME_COMPONENT(_absFile ${_lang}.po ABSOLUTE)
FILE(RELATIVE_PATH _relFile ${PROJECT_SOURCE_DIR} ${_absFile})
SET(_gmoFile ${CMAKE_BINARY_DIR}/translations/${_domain}/${_lang}.qm)

# Convert a PO file into a qm file.
ADD_CUSTOM_COMMAND(
OUTPUT ${_gmoFile}
COMMAND ${lconvert_executable} -i ${_absFile} -o ${_gmoFile}
DEPENDS ${_absFile}
)

INSTALL(FILES ${_gmoFile} DESTINATION ${SDATALOC}/translations/${_domain}/)
SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
ENDFOREACH (_lang)

# Create the .qm files when building the "translations-<DOMAIN>" and
# "translations" targets.
ADD_CUSTOM_TARGET(translations-${_domain} ${_addToAll} DEPENDS ${_gmoFiles})
ADD_DEPENDENCIES(translations translations-${_domain})
SET_TARGET_PROPERTIES(translations-${_domain} PROPERTIES FOLDER "po")
16 changes: 3 additions & 13 deletions src/core/StelTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,12 @@ void StelTranslator::initIso639_1LanguageCodes(const QString& fileName)
}
}

static constexpr char skyCulturePrefix[] = "stellarium-skycultures-";
StelSkyTranslator::StelSkyTranslator(const QString& skyCultureId, const QString& langName)
: commonSkyTranslator("stellarium-skycultures", langName)
: StelTranslator("stellarium-sky", langName)
, commonSkyTranslator("stellarium-skycultures", langName)
{
domain = skyCulturePrefix + skyCultureId;
this->langName = langName;
translator = new QTranslator();

const auto path = StelFileMgr::getInstallationDir() + "/skycultures/" + skyCultureId + "/translations/" + getTrueLocaleName()+".qm";
const bool res = translator->load(path);
if (!res)
qWarning() << "Couldn't load sky translations for language" << getTrueLocaleName() << "in sky culture" << skyCultureId;
if (translator->isEmpty())
qWarning() << "Empty translation file for language " << getTrueLocaleName() << "in sky culture" << skyCultureId;
if (commonSkyTranslator.isEmpty())
qWarning() << "Empty skyculture-independent translation file for language " << getTrueLocaleName() << "in sky culture" << skyCultureId;
qWarning() << "Empty skyculture-independent translation file for language " << getTrueLocaleName();
}

QString StelSkyTranslator::tryQtranslate(const QString& s, const QString& c) const
Expand Down

0 comments on commit 2e7402e

Please sign in to comment.