Skip to content

Commit 9a8889b

Browse files
committed
Make translations enable by default on all platforms
1 parent 91dd51d commit 9a8889b

7 files changed

Lines changed: 39 additions & 35 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ include_directories(
163163
vendor/SDL_ttf/include/
164164
)
165165

166+
# tinygettext
167+
set(BUILD_TESTS OFF)
168+
set(TINYGETTEXT_WITH_SDL OFF)
169+
set(TINYGETTEXT_UTF8_ONLY ON)
170+
171+
add_subdirectory(vendor/tinygettext)
172+
target_link_libraries(${PROJECT_NAME} PRIVATE
173+
tinygettext
174+
)
175+
include_directories(
176+
vendor/tinygettext/include/
177+
)
178+
166179
include_directories(
167180
${PROJECT_SOURCE_DIR}/include
168181
)
@@ -174,6 +187,7 @@ set(ASSETS_LEVELS "${CMAKE_SOURCE_DIR}/assets/levels")
174187
set(ASSETS_SOUNDS "${CMAKE_SOURCE_DIR}/assets/sounds")
175188
set(ASSETS_MUSIC "${CMAKE_SOURCE_DIR}/assets/music")
176189
set(ASSETS_BACKGROUNDS "${CMAKE_SOURCE_DIR}/assets/backgrounds")
190+
set(ASSETS_LANGUAGES "${CMAKE_SOURCE_DIR}/assets/languages")
177191

178192
if(PSP)
179193
set(ASSETS_BACKGROUNDS "${CMAKE_CURRENT_SOURCE_DIR}/platform/psp/assets/backgrounds")
@@ -207,6 +221,9 @@ if(NOT VITA)
207221
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
208222
COMMAND ${CMAKE_COMMAND} -E copy_directory
209223
${ASSETS_SOUNDS} ${CMAKE_CURRENT_BINARY_DIR}/assets/sounds)
224+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
225+
COMMAND ${CMAKE_COMMAND} -E copy_directory
226+
${ASSETS_LANGUAGES} ${CMAKE_CURRENT_BINARY_DIR}/assets/languages)
210227
endif()
211228

212229
# Generate credits file

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ When submitting a bug report, please make sure to include this information:
2323

2424
## Adding a new translation
2525

26-
By running cmake with the `-DTRANSLATION_SUPPORT=1` option, translation support can be enabled. To add a new language, for example German, you would run the following command:
26+
To add a new language, for example German, you would run the following command:
2727

2828
```
2929
platform/add-translation.sh de

src/TranslationManager.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#ifdef TRANSLATION_SUPPORT
2-
31
#include "TranslationManager.hpp"
42

53
#include <iostream>
@@ -48,24 +46,23 @@ void TranslationManager::loadTranslations() {
4846
std::vector<std::string> TranslationManager::getSystemLanguageList() {
4947
std::vector<std::string> locales;
5048

51-
SDL_Locale * preferred_locales = SDL_GetPreferredLocales();
52-
if(preferred_locales) {
53-
for (SDL_Locale * l = preferred_locales; l->language; l++) {
54-
std::string language = std::string(l->language);
55-
std::string country = "";
56-
if (l->country) {
57-
country = std::string(l->country);
58-
}
59-
std::string char_set = "UTF-8";
60-
std::string current_locale;
61-
if (country.empty()) {
62-
locales.push_back(language + "." + char_set);
63-
} else {
64-
locales.push_back(language + "_" + country + "." + char_set);
65-
locales.push_back(language + "_" + country);
66-
}
67-
locales.push_back(language);
49+
int locale_count = 0;
50+
SDL_Locale ** preferred_locales = SDL_GetPreferredLocales(&locale_count);
51+
for (int i = 0; i < locale_count ;i++) {
52+
std::string language = preferred_locales[i]->language;
53+
std::string country = "";
54+
if (preferred_locales[i]->country) {
55+
country = std::string(preferred_locales[i]->country);
6856
}
57+
std::string char_set = "UTF-8";
58+
std::string current_locale;
59+
if (country.empty()) {
60+
locales.push_back(language + "." + char_set);
61+
} else {
62+
locales.push_back(language + "_" + country + "." + char_set);
63+
locales.push_back(language + "_" + country);
64+
}
65+
locales.push_back(language);
6966
}
7067

7168
return locales;
@@ -78,5 +75,3 @@ std::string TranslationManager::translate(std::string input) {
7875
return input;
7976
}
8077
}
81-
82-
#endif // TRANSLATION_SUPPORT

src/TranslationManager.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef TRANSLATIONMANAGER_H
22
#define TRANSLATIONMANAGER_H
33

4-
#ifdef TRANSLATION_SUPPORT
54
#include <vector>
65

76
#include <tinygettext/tinygettext.hpp>
@@ -20,6 +19,5 @@ class TranslationManager {
2019

2120
std::string translate(std::string input);
2221
};
23-
#endif
2422

2523
#endif // TRANSLATIONMANAGER_H

src/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
#include "constants.hpp"
1818
#include "states/MenuState.hpp"
1919

20-
#ifdef TRANSLATION_SUPPORT
21-
// Create global TranslationManager object set in utils.h
22-
TranslationManager translation_manager;
23-
#endif
20+
// Create global TranslationManager object set in utils.h
21+
TranslationManager translation_manager;
2422

2523
void run() {
2624
OptionManager option_manager;

src/utils.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ std::string getResourcePath(std::string file);
2626
SDL_DisplayMode * getStandardDisplayMode();
2727
std::vector<SDL_DisplayMode*> getDisplayModes();
2828

29-
#ifdef TRANSLATION_SUPPORT
30-
extern TranslationManager translation_manager;
31-
#define _(x) translation_manager.translate(x)
32-
#else
33-
#define _(x) x
34-
#endif
29+
extern TranslationManager translation_manager;
30+
#define _(x) translation_manager.translate(x)
3531

3632
#endif // UTILS_HPP

0 commit comments

Comments
 (0)