Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locales init #563

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -235,6 +235,17 @@ else()
endif()
endif()

# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an option to disable even if all programs are available?

message (STATUS "Native language support enabled.")
add_definitions(-DHAVE_GETTEXT)
add_subdirectory (locale)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add an else message indicating 'Native language support disabled'?

add_definitions(-DINSTALLATION_PREFIX_DIR=\"${CMAKE_INSTALL_PREFIX}\")

#-------------------------------------------------------------------------------
# set up build directories
set(dir ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
34 changes: 30 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,28 @@ bool verifyHomeFolderExists()
return true;
}

void locales_init() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tabs vs 2 spaces

#ifdef HAVE_GETTEXT
char* btd;
char* cs;

#define LOCALEDIR INSTALLATION_PREFIX_DIR "/share/locale"
// local dir ; uncomment if you want to use locally compiled .mo files instead of .mo from the installation dir (present only after make install)
//#define LOCALEDIR "./locale/lang"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RetroPie doesn't rely on make install for installation. Can we make ./locale/lang the enabled option?


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 */
}
#endif
}

// Returns true if everything is OK,
bool loadSystemConfigFile(const char** errorString)
{
Expand Down Expand Up @@ -287,6 +310,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 +337,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 +359,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 +380,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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tabs vs 2 spaces

ss << strbuf;
}

mSystemInfo.setText(ss.str());
}, false, 1);
Expand Down
2 changes: 2 additions & 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 Expand Up @@ -88,6 +89,7 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/InputManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Log.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MameNames.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LocaleES.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/PowerSaver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Renderer_draw_gl.cpp
Expand Down
10 changes: 10 additions & 0 deletions es-core/src/LocaleES.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "LocaleES.h"

#ifndef HAVE_GETTEXT
char* ngettext(char* msgid, char* msgid_plural, unsigned long int n) {
if(n != 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tabs vs 2 spaces

return msgid_plural;
}
return msgid;
}
#endif
12 changes: 12 additions & 0 deletions es-core/src/LocaleES.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _LOCALE_H_
#define _LOCALE_H_

#ifdef HAVE_GETTEXT
#include <libintl.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tabs vs 2 spaces

#define _(A) gettext(A)
#else
#define _(A) A
char* ngettext(char* msgid, char* msgid_plural, unsigned long int n);
#endif

#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 ${CMAKE_CURRENT_SOURCE_DIR}/lang/*)
set(es_POT ${CMAKE_CURRENT_SOURCE_DIR}/emulationstation.pot)
# update the pot
MESSAGE("Building the pot file")
add_custom_command (TARGET i18n COMMAND find "${CMAKE_SOURCE_DIR}/es-app" "${CMAKE_SOURCE_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-07-19 10:06+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é."