Skip to content

Commit

Permalink
chore(i18n): Localization skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
mfep committed Jun 14, 2024
1 parent 275e11f commit eda4c28
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
51 changes: 49 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # option() honors normal variables

include(FetchContent)
include(external/CMakeRC.cmake)
include(GNUInstallDirs)

project(midiconn VERSION 0.2.2 LANGUAGES CXX)

Expand All @@ -20,7 +21,9 @@ endif()
if(NOT WIN32 AND MC_CHECK_FOR_UPDATES)
find_package(CURL REQUIRED)
endif()
find_package(Intl REQUIRED)

set(MC_LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")
configure_file(
src/Version.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/src/Version.hpp
Expand Down Expand Up @@ -92,7 +95,8 @@ target_include_directories(midiconn PRIVATE
external/imnodes
external/portable-file-dialogs
external/IconFontCppHeaders
"${FREETYPE_INCLUDE_DIRS}")
"${FREETYPE_INCLUDE_DIRS}"
"${Intl_INCLUDE_DIRS}")
target_link_libraries(midiconn PRIVATE
nlohmann_json::nlohmann_json
rtmidi
Expand All @@ -102,7 +106,8 @@ target_link_libraries(midiconn PRIVATE
fmt::fmt
freetype
resources
midi)
midi
"${Intl_LIBRARIES}")
if(NOT WIN32 AND MC_CHECK_FOR_UPDATES)
target_link_libraries(midiconn PRIVATE curl)
endif()
Expand Down Expand Up @@ -157,3 +162,45 @@ endif()
install(TARGETS midiconn
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
include(CPack)

find_program(XGETTEXT xgettext)
find_package(Gettext)
if (XGETTEXT AND ${GETTEXT_FOUND})
set(POT_FILE "${PROJECT_SOURCE_DIR}/po/midiconn.pot")
add_custom_command(
OUTPUT "${POT_FILE}"
COMMAND "${XGETTEXT}" "--join-existing" "--add-comments" "--output=${POT_FILE}" "--output-dir=${PROJECT_SOURCE_DIR}/po" ${sources}
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
DEPENDS ${sources}
)

file(GLOB PO_FILES "${PROJECT_SOURCE_DIR}/po/*.po")
if(PO_FILES)
foreach(PO_FILE ${PO_FILES})
add_custom_command(
OUTPUT "${PO_FILE}"
COMMAND "${GETTEXT_MSGMERGE_EXECUTABLE}" "--update" "--backup=off" "${PO_FILE}" "${POT_FILE}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
DEPENDS "${POT_FILE}"
)
endforeach()

add_custom_target(update-po DEPENDS ${PO_FILES})

foreach(PO_FILE ${PO_FILES})
cmake_path(GET PO_FILE STEM LANG)
set(MO_FILE "${CMAKE_BINARY_DIR}/${LANG}/midiconn.mo")
add_custom_command(
OUTPUT "${MO_FILE}"
COMMAND "${GETTEXT_MSGFMT_EXECUTABLE}" "--output-file=${MO_FILE}" "${PO_FILE}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
DEPENDS "${PO_FILE}"
)
add_custom_target(generate-mo-${LANG} ALL DEPENDS ${MO_FILE})
install(
FILES "${MO_FILE}"
DESTINATION "${MC_LOCALE_DIR}/${LANG}/LC_MESSAGES"
)
endforeach()
endif()
endif()
19 changes: 19 additions & 0 deletions po/midiconn.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-14 15:46+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

1 change: 1 addition & 0 deletions src/Version.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define MC_BUILD_OS "@CMAKE_SYSTEM_NAME@-@CMAKE_SYSTEM_PROCESSOR@"
#define MC_WEBSITE_URL "https://mfeproject.itch.io/midiconn"
#cmakedefine MC_CHECK_FOR_UPDATES
#define MC_LOCALE_DIR "@MC_LOCALE_DIR@"

namespace mc
{
Expand Down
17 changes: 17 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "KeyboardShortcutAggregator.hpp"
#include "PlatformUtils.hpp"
#include "Utils.hpp"
#include "Version.hpp"

#if !SDL_VERSION_ATLEAST(2, 0, 17)
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
Expand All @@ -38,6 +39,22 @@ MC_MAIN
spdlog::set_default_logger(rotating_logger);
spdlog::flush_every(3s);

if (setlocale(LC_ALL, "") == nullptr)
{
spdlog::error("Cannot set locale");
return -1;
}
if (bindtextdomain(MIDI_APPLICATION_NAME_SNAKE, MC_LOCALE_DIR) == nullptr)
{
spdlog::error("Cannot bind text domain");
return -1;
}
if (textdomain(MIDI_APPLICATION_NAME_SNAKE) == nullptr)
{
spdlog::error("Cannot set text domain");
return -1;
}

mc::platform::set_process_dpi_aware();

const auto file_to_open = mc::wrap_exception([&]() {
Expand Down

0 comments on commit eda4c28

Please sign in to comment.