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

Add support for translations in GDevelop 5 🌎 #919

Merged
merged 23 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ecf5401
Update to create-react-app v2
4ian Jan 31, 2019
02c65bc
[WIP] Add translations support, using js-lingui, to newIDE (including…
4ian Feb 2, 2019
a40ba25
Update README to add commands for updating translations
4ian Feb 4, 2019
0286f97
Add temporary translation files to .gitignore
4ian Feb 4, 2019
6908ab9
Fix ElectronEventsBridge regression (menus not working anymore)
4ian Feb 5, 2019
460946e
Add analyze-translations-coverage script
4ian Feb 5, 2019
3c81b3d
Internationalize a few files and add a script to codemod most newIDE …
4ian Feb 5, 2019
7729137
Upgrade to Storybook v4
4ian Feb 5, 2019
7250690
Fix issue with incompatible babel-loader version
4ian Feb 5, 2019
4323000
Fix ExampleJsExtension broken after internationalization
4ian Feb 7, 2019
c9e2d3f
Fix broken TimeExtension.cpp
4ian Feb 9, 2019
e8d9d4f
Use custom build of @lingui/react while waiting for new version for F…
4ian Feb 9, 2019
800d4f7
Fix Prettier and npm/yarn format command to exclude locales folder
4ian Feb 9, 2019
bef6f04
Run "codemod" to internationalize files
4ian Feb 5, 2019
9025d05
Fix translated dialog titles rendering and strings not to be translated
4ian Feb 6, 2019
0426bcb
Run Prettier
4ian Feb 9, 2019
c820194
Add LanguageDialog to choose language
4ian Feb 9, 2019
2c0253f
Improve translation handling and update all locale messages
4ian Feb 10, 2019
b4bd225
Exclude GDCpp messages from translations (as only used in old IDE)
4ian Feb 10, 2019
e98f252
Exclude deprecated extensions from translations
4ian Feb 10, 2019
a7afaa1
Update translations
4ian Feb 10, 2019
e7bca87
Update react-scripts and fix npm install
4ian Feb 12, 2019
fca6f76
Add unsafe-eval to fix issue with webpack for now
4ian Feb 16, 2019
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 @@ -9,6 +9,7 @@
/ExtLibs/*.7z
/scripts/Repository keys
/scripts/logs/*.txt
/scripts/gdcore-gdcpp-gdjs-extensions-messages.pot
/Binaries/.build*
/Binaries/.embuild*
/Binaries/build*
Expand Down
22 changes: 13 additions & 9 deletions Core/GDCore/Extensions/Builtin/TimeExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsTimeExtension(
.MarkAsAdvanced();

extension
.AddAction("ResetTimer",
_("Start (or reset) a scene timer"),
_("Reset the specified scene timer, if the timer doesn't exist "
"it's created and started."),
_("Reset the timer _PARAM1_"),
_("Timers and time"),
"res/actions/timer24.png",
"res/actions/timer.png")
.AddAction(
"ResetTimer",
_("Start (or reset) a scene timer"),
_("Reset the specified scene timer, if the timer doesn't exist "
"it's created and started."),
_("Reset the timer _PARAM1_"),
_("Timers and time"),
"res/actions/timer24.png",
"res/actions/timer.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("string", _("Timer's name"));

Expand Down Expand Up @@ -200,7 +201,10 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsTimeExtension(
"stringWithSelector",
_("Hour: hour - Minutes: min - Seconds: sec - Day of month: "
"mday - Months since January: mon - Year since 1900: year - Days "
"since Sunday: wday - Days since Jan 1st: yday - Timestamp (ms): timestamp\"), "[\"hour\", \"min\", \"sec\", \"mon\", \"year\", \"wday\", \"mday\", \"yday\", \"timestamp\"]");
"since Sunday: wday - Days since Jan 1st: yday - Timestamp (ms): "
"timestamp\""),
"[\"hour\", \"min\", \"sec\", \"mon\", \"year\", \"wday\", \"mday\", "
"\"yday\", \"timestamp\"]");

#endif
}
Expand Down
6 changes: 5 additions & 1 deletion Core/GDCore/Extensions/Metadata/InstructionMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

namespace gd {
InstructionMetadata::InstructionMetadata()
: sentence(_("Unknown or unsupported instruction")),
: sentence(
"Unknown or unsupported instruction"), // Avoid translating this
// string, so that it's safe
// and *fast* to use a
// InstructionMetadata.
canHaveSubInstructions(false),
hidden(true) {}

Expand Down
35 changes: 35 additions & 0 deletions Core/GDCore/Tools/Localization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* GDevelop Core
* Copyright 2008-present Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/

#if defined(EMSCRIPTEN)
#include <emscripten.h>
#include "GDCore/String.h"

namespace gd {
gd::String GetTranslation(const char* str) { // TODO: Inline?
const char* translatedStr = (const char*)EM_ASM_INT(
{
var getTranslation = Module['getTranslation'];
if (!getTranslation) {
return $0;
}

// Uncomment lines to display a warning if the cache
// for strings is not ready.
// if (!ensureCache) {
// console.warn('No ensureCache initialized');
// return $0;
// }
ensureCache.prepare();

var translatedStr = getTranslation(Pointer_stringify($0));
return ensureString(translatedStr);
},
str);
return gd::String(translatedStr); // TODO: Is copying necessary?
}
} // namespace gd
#endif
35 changes: 35 additions & 0 deletions Core/GDCore/Tools/Localization.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,55 @@
#ifndef GDCORE_LOCALIZATION_H
#define GDCORE_LOCALIZATION_H

/** @file
* Provide a way to mark strings to be translated.
*
* Strings to be translated in GDevelop Core codebase (and GDCpp),
* are marked with the underscore macro, for example: _("Hello World").
*
* The macro is then defined to be using the translation function
* of the underlying platform (Emscripten for GD5, wxWidgets for GD4,
* no translation for GDCpp Runtime).
*/

#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
// When compiling with wxWidgets, use the translation method
// provided by wxWidgets, but return a gd::String.

#include <wx/intl.h>
#include "GDCore/String.h"

// Create a new macro to return UTF8 gd::String from a translation
#if defined(_)
#undef _
#endif
#define _(s) gd::String(wxGetTranslation(wxString::FromUTF8(u8##s)))

#elif defined(EMSCRIPTEN)
// When compiling with Emscripten, use a translation function that is calling a
// JS method on the module, so that an external translation library can be used.

#include "GDCore/String.h"
#if defined(_)
#undef _
#endif

namespace gd {
gd::String GetTranslation(const char* str);
}

#define _(s) gd::GetTranslation(u8##s)

#else
// When compiling without Emscripten or wxWidgets (typically for GDC++ Runtime),
// just return an untranslated gd::String.

// Create a new macro to return UTF8 gd::String from a translation
#if defined(_)
#undef _
#endif
#define _(s) gd::String(u8##s)

#endif

#endif // GDCORE_LOCALIZATION_H
Loading