[apps/i18n] Remove Language::Default

We never translate a i18n message to something else than the currrent
language selected
This commit is contained in:
Léa Saviot
2020-04-06 11:41:26 +02:00
committed by EmilieNumworks
parent c58456a058
commit 19b5653851
6 changed files with 10 additions and 17 deletions

View File

@@ -1,5 +1,4 @@
#include "empty_battery_window.h"
#include "global_preferences.h"
#include <apps/i18n.h>
extern "C" {
#include <assert.h>
@@ -12,7 +11,7 @@ EmptyBatteryWindow::EmptyBatteryWindow() :
void EmptyBatteryWindow::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
const char * warningMessage = I18n::translate(I18n::Message::LowBattery, GlobalPreferences::sharedGlobalPreferences()->language());
const char * warningMessage = I18n::translate(I18n::Message::LowBattery);
KDSize warningSize = KDFont::LargeFont->stringSize(warningMessage);
ctx->drawString(warningMessage, KDPoint((Ion::Display::Width - warningSize.width())/2, (Ion::Display::Height - warningSize.height())/2), KDFont::LargeFont);
}

View File

@@ -95,7 +95,6 @@ def print_header(data, path, locales):
# Languages enumeration
f.write("enum class Language : uint16_t {\n")
f.write(" Default = 0,\n")
for locale in locales:
f.write(" " + locale.upper() + ",\n")
f.write("};\n\n")
@@ -159,21 +158,17 @@ def print_implementation(data, path, locales):
# Write the translate method
f.write("const char * translate(Message m, Language l) {\n")
f.write("const char * translate(Message m) {\n")
f.write(" assert(m != Message::LocalizedMessageMarker);\n")
f.write(" int localizedMessageOffset = (int)Message::LocalizedMessageMarker+1;\n")
f.write(" if ((int)m < localizedMessageOffset) {\n")
f.write(" assert(universalMessages[(int)m] != nullptr);\n")
f.write(" return universalMessages[(int)m];\n")
f.write(" }\n")
f.write(" int languageIndex = (int)l;\n")
f.write(" if (l == Language::Default) {\n")
f.write(" languageIndex = (int) GlobalPreferences::sharedGlobalPreferences()->language();\n")
f.write(" }\n")
f.write(" assert(languageIndex > 0);\n")
f.write(" int languageIndex = (int)GlobalPreferences::sharedGlobalPreferences()->language();\n")
f.write(" int messageIndex = (int)m - localizedMessageOffset;\n")
f.write(" assert((messageIndex*NumberOfLanguages+languageIndex-1)*sizeof(char *) < sizeof(messages));\n")
f.write(" return messages[messageIndex][languageIndex-1];\n")
f.write(" assert((messageIndex*NumberOfLanguages+languageIndex)*sizeof(char *) < sizeof(messages));\n")
f.write(" return messages[messageIndex][languageIndex];\n")
f.write("}\n\n")
f.write("}\n")
f.close()

View File

@@ -164,7 +164,7 @@ void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) {
MessageTableCell * myCell = (MessageTableCell *)cell;
myCell->setMessage(title);
if (index == k_indexOfLanguageCell) {
int index = (int)globalPreferences->language()-1;
int index = (int)(globalPreferences->language());
static_cast<MessageTableCellWithChevronAndMessage *>(cell)->setSubtitle(I18n::LanguageNames[index]);
return;
}

View File

@@ -18,8 +18,7 @@ LanguageController::LanguageController(Responder * parentResponder, KDCoordinate
void LanguageController::resetSelection() {
m_selectableTableView.deselectTable();
int index = (int)GlobalPreferences::sharedGlobalPreferences()->language()-1;
selectCellAtLocation(0, index);
selectCellAtLocation(0, (int)(GlobalPreferences::sharedGlobalPreferences()->language()));
}
const char * LanguageController::title() {
@@ -41,7 +40,7 @@ void LanguageController::viewWillAppear() {
bool LanguageController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
GlobalPreferences::sharedGlobalPreferences()->setLanguage((I18n::Language)(selectedRow()+1));
GlobalPreferences::sharedGlobalPreferences()->setLanguage((I18n::Language)selectedRow());
/* We need to reload the whole title bar in order to translate both the
* "Settings" title and the degree preference. */
AppsContainer::sharedAppsContainer()->reloadTitleBarView();

View File

@@ -6,7 +6,7 @@
namespace I18n {
enum class Message : uint16_t;
enum class Language : uint16_t;
const char * translate(Message m, Language l = (Language)0);
const char * translate(Message m);
int numberOfLanguages();
}

View File

@@ -2,7 +2,7 @@
namespace I18n {
const char * translate(Message m, Language l) {
const char * translate(Message m) {
return nullptr;
}