From a9b183729fd207d9441c682280b5a5a7e6867196 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 17 Oct 2017 18:00:45 -0300 Subject: [PATCH] Translate all alerts to the en.ini file (#124) --- data/strings/en.ini | 131 +++++++++++++++++++ src/app/commands/cmd_export_sprite_sheet.cpp | 8 +- src/app/commands/cmd_import_sprite_sheet.cpp | 8 +- src/app/commands/cmd_keyboard_shortcuts.cpp | 16 +-- src/app/commands/cmd_load_mask.cpp | 9 +- src/app/commands/cmd_load_palette.cpp | 4 +- src/app/commands/cmd_options.cpp | 50 ++++--- src/app/commands/cmd_paste_text.cpp | 4 +- src/app/commands/cmd_remove_layer.cpp | 7 +- src/app/commands/cmd_save_file.cpp | 6 +- src/app/commands/cmd_save_mask.cpp | 4 +- src/app/commands/cmd_save_palette.cpp | 4 +- src/app/commands/filters/filter_worker.cpp | 6 +- src/app/file/ase_format.cpp | 20 +-- src/app/file/file.cpp | 66 +++++----- src/app/i18n/strings.cpp | 4 +- src/app/i18n/strings.h | 8 +- src/app/job.cpp | 7 +- src/app/launcher.cpp | 8 +- src/app/send_crash.cpp | 8 +- src/app/ui/color_bar.cpp | 7 +- src/app/ui/data_recovery_view.cpp | 9 +- src/app/ui/document_view.cpp | 14 +- src/app/ui/editor/tool_loop_impl.cpp | 13 +- src/app/ui/file_selector.cpp | 29 ++-- src/app/ui/timeline/timeline.cpp | 4 +- src/app/util/clipboard_native.cpp | 7 +- src/gen/strings_class.cpp | 4 +- src/ui/alert.cpp | 30 ++--- src/ui/alert.h | 6 +- 30 files changed, 320 insertions(+), 181 deletions(-) diff --git a/data/strings/en.ini b/data/strings/en.ini index 83c6ba96f..8782f3095 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -6,6 +6,137 @@ title = Warning - Important description = You are going to enter in "Advanced Mode". dont_show_again = Don't show this again +[alerts] +applying_filter = FX< Save As menu option in that case. +||&OK +END +cannot_open_file = Problem< {2}% +<< UI Scaling: {3}% -> {4}% +<accels()[index]; - if (Alert::show( - "Warning" - "<disableAccel(accel); @@ -586,10 +587,7 @@ private: } void onReset() { - if (Alert::show("Warning" - "<reset(); layout(); } diff --git a/src/app/commands/cmd_load_mask.cpp b/src/app/commands/cmd_load_mask.cpp index 71f8ff1e4..fbfc2380a 100644 --- a/src/app/commands/cmd_load_mask.cpp +++ b/src/app/commands/cmd_load_mask.cpp @@ -13,11 +13,13 @@ #include "app/commands/params.h" #include "app/context_access.h" #include "app/file_selector.h" +#include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/transaction.h" #include "app/util/msk_file.h" #include "doc/mask.h" #include "doc/sprite.h" +#include "fmt/format.h" #include "ui/alert.h" namespace app { @@ -68,9 +70,10 @@ void LoadMaskCommand::onExecute(Context* context) } base::UniquePtr mask(load_msk_file(m_filename.c_str())); - if (!mask) - throw base::Exception("Error loading .msk file: %s", - static_cast(m_filename.c_str())); + if (!mask) { + ui::Alert::show(fmt::format(Strings::alerts_error_loading_file(), m_filename)); + return; + } { ContextWriter writer(reader); diff --git a/src/app/commands/cmd_load_palette.cpp b/src/app/commands/cmd_load_palette.cpp index ff584d13b..071d033f8 100644 --- a/src/app/commands/cmd_load_palette.cpp +++ b/src/app/commands/cmd_load_palette.cpp @@ -14,10 +14,12 @@ #include "app/context.h" #include "app/file/palette_file.h" #include "app/file_selector.h" +#include "app/i18n/strings.h" #include "app/modules/palettes.h" #include "base/fs.h" #include "base/unique_ptr.h" #include "doc/palette.h" +#include "fmt/format.h" #include "ui/alert.h" namespace app { @@ -80,7 +82,7 @@ void LoadPaletteCommand::onExecute(Context* context) base::UniquePtr palette(load_palette(filename.c_str())); if (!palette) { if (context->isUIAvailable()) - Alert::show("Error<isSelected()); m_pref.general.dataRecoveryPeriod(newPeriod); - warnings += "<<- Automatically save recovery data every"; + warnings += "<<- " + Strings::alerts_restart_by_preferences_save_recovery_data_period(); } m_pref.editor.zoomFromCenterWithWheel(zoomFromCenterWithWheel()->isSelected()); @@ -463,9 +465,9 @@ public: m_pref.save(); if (!warnings.empty()) { - ui::Alert::show(PACKAGE - "< %d%%" - "<< UI Scaling: %d%% -> %d%%" - "< 0 ? newScreenScale: m_pref.general.screenScale()), - 100 * m_pref.general.uiScale(), - 100 * (newUIScale > 0 ? newUIScale: m_pref.general.uiScale())); + fmt::format( + Strings::alerts_update_screen_ui_scaling_with_theme_values(), + themeName, + 100 * m_pref.general.screenScale(), + 100 * (newScreenScale > 0 ? newScreenScale: m_pref.general.screenScale()), + 100 * m_pref.general.uiScale(), + 100 * (newUIScale > 0 ? newUIScale: m_pref.general.uiScale()))); if (result == 1) { // Preferred UI Scaling factor @@ -865,14 +863,13 @@ private: // Uninstall? if (ui::Alert::show( - "Update Extension" - "<name().c_str(), - (isDowngrade ? "downgrade": "upgrade"), - ext->version().c_str(), - info.version.c_str()) != 1) + fmt::format( + Strings::alerts_update_extension(), + ext->name(), + (isDowngrade ? Strings::alerts_update_extension_downgrade(): + Strings::alerts_update_extension_upgrade()), + ext->version(), + info.version)) != 1) return; // Uninstall old version @@ -917,10 +914,9 @@ private: return; if (ui::Alert::show( - "Warning" - "<text().c_str()) != 1) + fmt::format( + Strings::alerts_uninstall_extension_warning(), + item->text())) != 1) return; try { diff --git a/src/app/commands/cmd_paste_text.cpp b/src/app/commands/cmd_paste_text.cpp index 560450c2a..3af916037 100644 --- a/src/app/commands/cmd_paste_text.cpp +++ b/src/app/commands/cmd_paste_text.cpp @@ -195,9 +195,7 @@ void PasteTextCommand::onExecute(Context* ctx) } } catch (const std::exception& ex) { - ui::Alert::show(PACKAGE - "<<%s" - "||&OK", ex.what()); + Console::showException(ex); } } diff --git a/src/app/commands/cmd_remove_layer.cpp b/src/app/commands/cmd_remove_layer.cpp index 881acdc53..2280e8849 100644 --- a/src/app/commands/cmd_remove_layer.cpp +++ b/src/app/commands/cmd_remove_layer.cpp @@ -12,9 +12,10 @@ #include "app/commands/command.h" #include "app/context_access.h" #include "app/document_api.h" +#include "app/i18n/strings.h" #include "app/modules/gui.h" -#include "app/ui/status_bar.h" #include "app/transaction.h" +#include "app/ui/status_bar.h" #include "doc/layer.h" #include "doc/sprite.h" #include "ui/alert.h" @@ -69,7 +70,7 @@ void RemoveLayerCommand::onExecute(Context* context) } if (deletedTopLevelLayers == sprite->root()->layersCount()) { - ui::Alert::show("Error<allLayersCount() == 1) { - ui::Alert::show("Error< Save menu option in that case." - "||&OK"); + ui::Alert::show(Strings::alerts_cannot_file_overwrite_on_export()); goto again; } diff --git a/src/app/commands/cmd_save_mask.cpp b/src/app/commands/cmd_save_mask.cpp index 6a6628614..53e07f3a5 100644 --- a/src/app/commands/cmd_save_mask.cpp +++ b/src/app/commands/cmd_save_mask.cpp @@ -11,10 +11,12 @@ #include "app/commands/command.h" #include "app/context_access.h" #include "app/file_selector.h" +#include "app/i18n/strings.h" #include "app/util/msk_file.h" #include "base/fs.h" #include "doc/mask.h" #include "doc/sprite.h" +#include "fmt/format.h" #include "ui/alert.h" namespace app { @@ -55,7 +57,7 @@ void SaveMaskCommand::onExecute(Context* context) std::string filename = selFilename.front(); if (save_msk_file(document->mask(), filename.c_str()) != 0) - ui::Alert::show("Error<addProgress(); m_timer.Tick.connect(&FilterWorker::onMonitoringTick, this); diff --git a/src/app/file/ase_format.cpp b/src/app/file/ase_format.cpp index cb28e5ca2..c1baaaa6b 100644 --- a/src/app/file/ase_format.cpp +++ b/src/app/file/ase_format.cpp @@ -20,6 +20,7 @@ #include "base/fs.h" #include "doc/doc.h" #include "fixmath/fixmath.h" +#include "fmt/format.h" #include "ui/alert.h" #include "zlib.h" @@ -403,14 +404,17 @@ bool AseFormat::onPostLoad(FileOp* fop) if (flat && ase_has_groups(group)) { if (fop->context() && fop->context()->isUIAvailable() && - ui::Alert::show("Warning" - "<filename()).c_str(), - PACKAGE, ver.c_str()) != 1) { + ui::Alert::show( + fmt::format( + // This message is not translated because is used only in the old v1.1 only + "Warning" + "<filename()), + PACKAGE, ver)) != 1) { return false; } ase_ungroup_all(group); diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index 8be82f128..5b07b2586 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -19,6 +19,7 @@ #include "app/file/format_options.h" #include "app/file/split_filename.h" #include "app/filename_formatter.h" +#include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/modules/palettes.h" #include "app/ui/status_bar.h" @@ -29,6 +30,7 @@ #include "base/string.h" #include "dio/detect_format.h" #include "doc/doc.h" +#include "fmt/format.h" #include "render/quantization.h" #include "render/render.h" #include "ui/alert.h" @@ -327,6 +329,13 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context, // Get the extension of the filename (in lower case) LOG("FILE: Saving document \"%s\"\n", filename.c_str()); + // Check for read-only attribute + if (base::has_readonly_attr(filename)) { + fop->setError("Error saving \"%s\" file, it's read-only", + filename.c_str()); + return fop.release(); + } + // Get the format through the extension of the filename fop->m_format = FileFormatsManager::instance()->getFileFormat( dio::detect_format_by_file_extension(filename)); @@ -347,32 +356,32 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context, case IMAGE_RGB: if (!(fop->m_format->support(FILE_SUPPORT_RGB))) { - warnings += "<<- RGB format"; + warnings += "<<- " + Strings::alerts_file_format_rgb_mode(); fatal = true; } if (!(fop->m_format->support(FILE_SUPPORT_RGBA)) && fop->m_document->sprite()->needAlpha()) { - warnings += "<<- Alpha channel"; + warnings += "<<- " + Strings::alerts_file_format_alpha_channel(); } break; case IMAGE_GRAYSCALE: if (!(fop->m_format->support(FILE_SUPPORT_GRAY))) { - warnings += "<<- Grayscale format"; + warnings += "<<- " + Strings::alerts_file_format_grayscale_mode(); fatal = true; } if (!(fop->m_format->support(FILE_SUPPORT_GRAYA)) && fop->m_document->sprite()->needAlpha()) { - warnings += "<<- Alpha channel"; + warnings += "<<- " + Strings::alerts_file_format_alpha_channel(); } break; case IMAGE_INDEXED: if (!(fop->m_format->support(FILE_SUPPORT_INDEXED))) { - warnings += "<<- Indexed format"; + warnings += "<<- " + Strings::alerts_file_format_indexed_mode(); fatal = true; } break; @@ -382,14 +391,14 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context, if (fop->m_roi.frames() > 1) { if (!fop->m_format->support(FILE_SUPPORT_FRAMES) && !fop->m_format->support(FILE_SUPPORT_SEQUENCES)) { - warnings += "<<- Frames"; + warnings += "<<- " + Strings::alerts_file_format_frames(); } } // Layers support if (fop->m_document->sprite()->root()->layersCount() > 1) { if (!(fop->m_format->support(FILE_SUPPORT_LAYERS))) { - warnings += "<<- Layers"; + warnings += "<<- " + Strings::alerts_file_format_layers(); } } @@ -397,14 +406,14 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context, if (fop->m_document->sprite()->getPalettes().size() > 1) { if (!fop->m_format->support(FILE_SUPPORT_PALETTES) && !fop->m_format->support(FILE_SUPPORT_SEQUENCES)) { - warnings += "<<- Palette changes between frames"; + warnings += "<<- " + Strings::alerts_file_format_palette_changes(); } } // Check frames support if (!fop->m_document->sprite()->frameTags().empty()) { if (!fop->m_format->support(FILE_SUPPORT_FRAME_TAGS)) { - warnings += "<<- Frame tags"; + warnings += "<<- " + Strings::alerts_file_format_frame_tags(); } } @@ -438,26 +447,12 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context, if (!warnings.empty()) { // Interative if (context && context->isUIAvailable()) { - warnings += "<m_format->name(), - warnings.c_str(), - fop->m_format->name(), - buttons.c_str()); + int ret = ui::Alert::show( + fmt::format( + (fatal ? Strings::alerts_file_format_doesnt_support_error(): + Strings::alerts_file_format_doesnt_support_warning()), + fop->m_format->name(), + warnings)); // Operation can't be done (by fatal error) or the user cancel // the operation @@ -510,13 +505,12 @@ FileOp* FileOp::createSaveDocumentOperation(const Context* context, if (context && context->isUIAvailable() && fop->m_seq.filename_list.size() > 1 && - ui::Alert::show("Notice" - "<m_seq.filename_list.size()), - base::get_file_name(fop->m_seq.filename_list[0]).c_str(), - base::get_file_name(fop->m_seq.filename_list[1]).c_str()) != 1) { + ui::Alert::show( + fmt::format( + Strings::alerts_export_animation_in_sequence(), + int(fop->m_seq.filename_list.size()), + base::get_file_name(fop->m_seq.filename_list[0]), + base::get_file_name(fop->m_seq.filename_list[1]))) != 1) { return nullptr; } } diff --git a/src/app/i18n/strings.cpp b/src/app/i18n/strings.cpp index 23bebc0e4..8663d6291 100644 --- a/src/app/i18n/strings.cpp +++ b/src/app/i18n/strings.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2016 David Capello +// Copyright (C) 2016, 2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -61,7 +61,7 @@ Strings::Strings() } } -const std::string& Strings::translate(const char* id) +const std::string& Strings::translate(const char* id) const { auto it = m_strings.find(id); if (it != m_strings.end()) diff --git a/src/app/i18n/strings.h b/src/app/i18n/strings.h index b371f41b0..52c9ff182 100644 --- a/src/app/i18n/strings.h +++ b/src/app/i18n/strings.h @@ -16,17 +16,17 @@ namespace app { - // Singleton class to load and access "strings/english.txt" file. - class Strings { + // Singleton class to load and access "strings/en.ini" file. + class Strings : public app::gen::Strings { public: static Strings* instance(); - const std::string& translate(const char* id); + const std::string& translate(const char* id) const; private: Strings(); - std::unordered_map m_strings; + mutable std::unordered_map m_strings; }; } // namespace app diff --git a/src/app/job.cpp b/src/app/job.cpp index 2038ca0f9..8c4a77b49 100644 --- a/src/app/job.cpp +++ b/src/app/job.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -12,9 +12,11 @@ #include "app/app.h" #include "app/console.h" +#include "app/i18n/strings.h" #include "base/mutex.h" #include "base/scoped_lock.h" #include "base/thread.h" +#include "fmt/format.h" #include "ui/alert.h" #include "ui/widget.h" #include "ui/window.h" @@ -43,7 +45,8 @@ Job::Job(const char* jobName) m_mutex = new base::mutex(); if (App::instance()->isGui()) { - m_alert_window = ui::Alert::create("%s<addProgress(); m_timer.reset(new ui::Timer(kMonitoringPeriod, m_alert_window.get())); diff --git a/src/app/launcher.cpp b/src/app/launcher.cpp index b93a289c6..8ca6a75fb 100644 --- a/src/app/launcher.cpp +++ b/src/app/launcher.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2015, 2017 David Capello // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -10,8 +10,10 @@ #include "app/launcher.h" +#include "app/i18n/strings.h" #include "base/exception.h" #include "base/launcher.h" +#include "fmt/format.h" #include "ui/alert.h" namespace app { @@ -25,13 +27,13 @@ void open_url(const std::string& url) void open_file(const std::string& file) { if (!base::launcher::open_file(file)) - ui::Alert::show("Problem<isModified()) { // ask what want to do the user with the changes in the sprite - int ret = Alert::show("Warning" - "<name().c_str(), - quitting ? "quitting": "closing"); + int ret = Alert::show( + fmt::format( + Strings::alerts_save_sprite_changes(), + m_document->name(), + (quitting ? Strings::alerts_save_sprite_changes_quitting(): + Strings::alerts_save_sprite_changes_closing()))); if (ret == 1) { // "save": save the changes diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index 8374d0014..9bab2a410 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -20,6 +20,7 @@ #include "app/context.h" #include "app/context_access.h" #include "app/document_undo.h" +#include "app/i18n/strings.h" #include "app/modules/gui.h" #include "app/modules/palettes.h" #include "app/pref/preferences.h" @@ -48,6 +49,7 @@ #include "doc/remap.h" #include "doc/slice.h" #include "doc/sprite.h" +#include "fmt/format.h" #include "render/dithering.h" #include "render/render.h" #include "ui/ui.h" @@ -591,10 +593,7 @@ tools::ToolLoop* create_tool_loop( app::Color bg = colorbar->getBgColor(); if (!fg.isValid() || !bg.isValid()) { - Alert::show(PACKAGE - "< |" + " \\ : * ? \" < > |" #endif - "||&OK"); + ; + + ui::Alert::show( + fmt::format( + Strings::alerts_invalid_chars_in_filename(), + invalid_chars)); // show the window again setVisible(true); @@ -646,8 +652,10 @@ again: } if (m_type == FileSelectorType::Save && base::is_file(buf)) { - int ret = Alert::show("Warning<(this)->translate(\"" << textId << "\"); }\n"; + std::cout << " static const std::string& " << to_cpp(textId) << "() { return T::instance()->translate(\"" << textId << "\"); }\n"; textId.erase(section.size()+1); } diff --git a/src/ui/alert.cpp b/src/ui/alert.cpp index 47ea9767f..dfd7cdf89 100644 --- a/src/ui/alert.cpp +++ b/src/ui/alert.cpp @@ -45,7 +45,6 @@ #include "ui/slider.h" #include "ui/theme.h" -#include #include namespace ui { @@ -73,13 +72,10 @@ void Alert::setProgress(double progress) m_progress->setValue(int(MID(0.0, progress * 100.0, 100.0))); } -AlertPtr Alert::create(const char* format, ...) +// static +AlertPtr Alert::create(const std::string& _msg) { - // Process arguments - std::va_list ap; - va_start(ap, format); - std::string msg = base::string_vprintf(format, ap); - va_end(ap); + std::string msg(_msg); // Create the alert window AlertPtr window(new Alert()); @@ -88,13 +84,9 @@ AlertPtr Alert::create(const char* format, ...) } // static -int Alert::show(const char* format, ...) +int Alert::show(const std::string& _msg) { - // Process arguments - std::va_list ap; - va_start(ap, format); - std::string msg = base::string_vprintf(format, ap); - va_end(ap); + std::string msg(_msg); // Create the alert window AlertPtr window(new Alert()); @@ -134,7 +126,14 @@ void Alert::processString(std::string& buf) // Process buffer c = 0; beg = 0; - for (; ; c++) { + for (;;) { + // Ignore characters + if (buf[c] == '\n' || + buf[c] == '\r') { + buf.erase(c, 1); + continue; + } + if ((!buf[c]) || ((buf[c] == buf[c+1]) && ((buf[c] == '<') || @@ -185,9 +184,10 @@ void Alert::processString(std::string& buf) case '-': separator=true; break; case '|': button=true; break; } - c++; + ++c; } } + ++c; } auto box1 = new Box(VERTICAL); diff --git a/src/ui/alert.h b/src/ui/alert.h index 37c30709f..99bb6ebe0 100644 --- a/src/ui/alert.h +++ b/src/ui/alert.h @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -31,8 +31,8 @@ namespace ui { int show(); - static AlertPtr create(const char* format, ...); - static int show(const char* format, ...); + static AlertPtr create(const std::string& msg); + static int show(const std::string& msg); private: void processString(std::string& buf);