Skip to content

Commit

Permalink
locales init
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Adenis-Lamarre <[email protected]>
  • Loading branch information
nadenislamarre committed May 12, 2019
1 parent 9d793db commit 6a2324b
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.slo
*.lo
*.o
*.mo

# Compiled Dynamic libraries
*.so
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,14 @@ set(LIBRARY_OUTPUT_PATH ${dir} CACHE PATH "Build directory" FORCE)
add_subdirectory("external")
add_subdirectory("es-core")
add_subdirectory("es-app")

# i18n
# i18n
find_program (MSGFMT_EXECUTABLE msgfmt)
find_program (MSGMERGE_EXECUTABLE msgmerge)
find_program (XGETTEXT_EXECUTABLE xgettext)
if(MSGFMT_EXECUTABLE AND MSGMERGE_EXECUTABLE AND XGETTEXT_EXECUTABLE)
message (STATUS "Native language support enabled.")
add_subdirectory (locale)
endif()

32 changes: 28 additions & 4 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifdef WIN32
#include <Windows.h>
#endif
#include "LocaleES.h"

#include <FreeImage.h>

Expand Down Expand Up @@ -196,6 +197,26 @@ bool verifyHomeFolderExists()
return true;
}

void locales_init() {
char* btd;
char* cs;

#define LOCALEDIR "/usr/share/locale"
// local dir
//#define LOCALEDIR "./locale/lang"

setlocale (LC_MESSAGES, "");
textdomain("emulationstation");
if((btd=bindtextdomain("emulationstation", LOCALEDIR)) == NULL) {
return;
}

cs = bind_textdomain_codeset("emulationstation", "UTF-8");
if(cs == NULL) {
/* outch not enough memory, no real thing to do */
}
}

// Returns true if everything is OK,
bool loadSystemConfigFile(const char** errorString)
{
Expand Down Expand Up @@ -287,6 +308,9 @@ int main(int argc, char* argv[])
//always close the log on exit
atexit(&onExit);

// Set locale
locales_init();

Window window;
SystemScreenSaver screensaver(&window);
PowerSaver::init();
Expand All @@ -311,9 +335,9 @@ int main(int argc, char* argv[])
LOG(LogInfo) << " ARB_texture_non_power_of_two: " << (glExts.find("ARB_texture_non_power_of_two") != std::string::npos ? "ok" : "MISSING");
if(splashScreen)
{
std::string progressText = "Loading...";
std::string progressText = _("Loading...");
if (splashScreenProgress)
progressText = "Loading system config...";
progressText = _("Loading system config...");
window.renderLoadingScreen(progressText);
}
}
Expand All @@ -333,7 +357,7 @@ int main(int argc, char* argv[])
// we can't handle es_systems.cfg file problems inside ES itself, so display the error message then quit
window.pushGui(new GuiMsgBox(&window,
errorMsg,
"QUIT", [] {
_("QUIT"), [] {
SDL_Event* quit = new SDL_Event();
quit->type = SDL_QUIT;
SDL_PushEvent(quit);
Expand All @@ -354,7 +378,7 @@ int main(int argc, char* argv[])
ViewController::get()->preload();

if(splashScreen && splashScreenProgress)
window.renderLoadingScreen("Done.");
window.renderLoadingScreen(_("Done."));

//choose which GUI to open depending on if an input configuration already exists
if(errorMsg == NULL)
Expand Down
8 changes: 6 additions & 2 deletions es-app/src/views/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Settings.h"
#include "SystemData.h"
#include "Window.h"
#include "LocaleES.h"

// buffer values for scrolling velocity (left, stopped, right)
const int logoBuffersLeft[] = { -5, -2, -1 };
Expand Down Expand Up @@ -255,11 +256,14 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
// also change the text after we've fully faded out
setAnimation(infoFadeOut, 0, [this, gameCount] {
std::stringstream ss;
char strbuf[256];

if (!getSelected()->isGameSystem())
ss << "CONFIGURATION";
else
ss << gameCount << " GAMES AVAILABLE";
else {
snprintf(strbuf, 256, ngettext("%i GAME AVAILABLE", "%i GAMES AVAILABLE", gameCount), gameCount);
ss << strbuf;
}

mSystemInfo.setText(ss.str());
}, false, 1);
Expand Down
1 change: 1 addition & 0 deletions es-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.h
${CMAKE_CURRENT_SOURCE_DIR}/src/MameNames.h
${CMAKE_CURRENT_SOURCE_DIR}/src/LocaleES.h
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.h
${CMAKE_CURRENT_SOURCE_DIR}/src/PowerSaver.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer.h
Expand Down
8 changes: 8 additions & 0 deletions es-core/src/LocaleES.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _LOCALE_H_
#define _LOCALE_H_

#include <libintl.h>

#define _(A) gettext(A)

#endif
17 changes: 17 additions & 0 deletions locale/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_custom_target (i18n ALL COMMENT "Building i18n messages.")
file (GLOB es_PO_FILES ${dir}/locale/lang/*)
set(es_POT ${dir}/locale/emulationstation.pot)
# update the pot
MESSAGE("Building the pot file")
add_custom_command (TARGET i18n COMMAND find "${dir}/es-app" "${dir}/es-core" -name "*.cpp" -o -name "*.h" | ${XGETTEXT_EXECUTABLE} -f - -o ${es_POT} --no-location --keyword=_)

foreach (es_PO_INPUT ${es_PO_FILES})
get_filename_component (es_PO_LANG ${es_PO_INPUT} NAME_WE)
MESSAGE("LANG = ${es_PO_LANG}")
set (es_MO_OUTPUT ${es_PO_INPUT}/LC_MESSAGES/emulationstation.mo)
# update the po from the pot
add_custom_command (TARGET i18n COMMAND basename ${es_PO_INPUT} && ${MSGMERGE_EXECUTABLE} -U --no-fuzzy-matching ${es_PO_INPUT}/LC_MESSAGES/emulationstation.po ${es_POT})
# compile the po to mo
add_custom_command (TARGET i18n COMMAND ${MSGFMT_EXECUTABLE} -o ${es_MO_OUTPUT} ${es_PO_INPUT}/LC_MESSAGES/emulationstation.po --statistics)
install (FILES ${es_MO_OUTPUT} DESTINATION share/locale/${es_PO_LANG}/LC_MESSAGES RENAME emulationstation.mo)
endforeach (es_PO_INPUT ${es_PO_FILES})
10 changes: 10 additions & 0 deletions locale/checkLocale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

(cd lang &&
for POLANG in *
do
POFILE="./${POLANG}/LC_MESSAGES/emulationstation.po"
echo -n "${POLANG}: "
LANG=C msgfmt "${POFILE}" -o - --statistics > /dev/null
done
)
37 changes: 37 additions & 0 deletions locale/emulationstation.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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: 2019-05-12 22:26+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#, c-format
msgid "%i GAME AVAILABLE"
msgid_plural "%i GAMES AVAILABLE"
msgstr[0] ""
msgstr[1] ""

msgid "Loading..."
msgstr ""

msgid "Loading system config..."
msgstr ""

msgid "QUIT"
msgstr ""

msgid "Done."
msgstr ""
29 changes: 29 additions & 0 deletions locale/lang/fr/LC_MESSAGES/emulationstation.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
msgid ""
msgstr ""
"Project-Id-Version: emulationstation\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-05-12 22:25+0200\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: POEditor.com\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#, c-format
msgid "%i GAME AVAILABLE"
msgid_plural "%i GAMES AVAILABLE"
msgstr[0] "%i JEU DISPONIBLE"
msgstr[1] "%i JEUX DISPONIBLES"

msgid "Loading..."
msgstr "Chargement..."

msgid "Loading system config..."
msgstr "Chargement de la configuration système"

msgid "QUIT"
msgstr "QUITTER"

msgid "Done."
msgstr "Terminé."

0 comments on commit 6a2324b

Please sign in to comment.