From f4ffd4110c996138bf2b0a652fbae9dbb08f0320 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 9 Oct 2017 14:43:01 -0300 Subject: [PATCH] Start using fmt library This is the first step for a full i18n (#124). --- .gitmodules | 3 +++ docs/LICENSES.md | 28 ++++++++++++++++++++++++++++ src/app/CMakeLists.txt | 3 ++- src/app/i18n/strings.h | 4 +--- src/app/ui/home_view.cpp | 6 ++++-- third_party/CMakeLists.txt | 1 + third_party/fmt | 1 + 7 files changed, 40 insertions(+), 6 deletions(-) create mode 160000 third_party/fmt diff --git a/.gitmodules b/.gitmodules index 847afe966..49148de02 100644 --- a/.gitmodules +++ b/.gitmodules @@ -57,3 +57,6 @@ [submodule "third_party/giflib"] path = third_party/giflib url = https://github.com/aseprite/giflib.git +[submodule "third_party/fmt"] + path = third_party/fmt + url = https://github.com/aseprite/fmt.git diff --git a/docs/LICENSES.md b/docs/LICENSES.md index 87f95fe60..b5e9a9545 100644 --- a/docs/LICENSES.md +++ b/docs/LICENSES.md @@ -230,6 +230,34 @@ be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder. ``` +# [fmt](https://github.com/fmtlib/fmt) + +``` +Copyright (c) 2012 - 2016, Victor Zverovich + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +``` + # [FreeType](http://www.freetype.org/) ``` diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index bbf406e48..d7915ddc4 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -554,7 +554,8 @@ target_link_libraries(app-lib ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES} json11 - archive_static) + archive_static + fmt) if(ENABLE_SCRIPTING) target_link_libraries(app-lib script-lib) diff --git a/src/app/i18n/strings.h b/src/app/i18n/strings.h index c85bc2a5b..b371f41b0 100644 --- a/src/app/i18n/strings.h +++ b/src/app/i18n/strings.h @@ -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. @@ -29,8 +29,6 @@ namespace app { std::unordered_map m_strings; }; - #define tr(id) (Strings::instance()->translate(id)) - } // namespace app #endif diff --git a/src/app/ui/home_view.cpp b/src/app/ui/home_view.cpp index 524480008..beddabc74 100644 --- a/src/app/ui/home_view.cpp +++ b/src/app/ui/home_view.cpp @@ -24,6 +24,7 @@ #include "app/ui_context.h" #include "base/bind.h" #include "base/exception.h" +#include "fmt/format.h" #include "ui/label.h" #include "ui/resize_event.h" #include "ui/system.h" @@ -143,7 +144,7 @@ void HomeView::onCheckingUpdates() void HomeView::onUpToDate() { - checkUpdate()->setText(PACKAGE " is up to date"); + checkUpdate()->setText(fmt::format("{0} is up to date", PACKAGE)); checkUpdate()->setVisible(true); layout(); @@ -151,7 +152,8 @@ void HomeView::onUpToDate() void HomeView::onNewUpdate(const std::string& url, const std::string& version) { - checkUpdate()->setText("New " PACKAGE " v" + version + " available!"); + checkUpdate()->setText(fmt::format("New {0} v{1} available!", + PACKAGE, version)); checkUpdate()->setUrl(url); checkUpdate()->setVisible(true); checkUpdate()->InitTheme.connect( diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 596ffa2e4..bda297fa6 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -88,6 +88,7 @@ endif() add_subdirectory(harfbuzz-cmake) add_subdirectory(simpleini) +add_subdirectory(fmt) # Add cmark without tests if(NOT USE_SHARED_CMARK) diff --git a/third_party/fmt b/third_party/fmt new file mode 160000 index 000000000..933a33a79 --- /dev/null +++ b/third_party/fmt @@ -0,0 +1 @@ +Subproject commit 933a33a7948c3d9bb984473b9b92832f52c590cd