~aleteoryx/muditaos

695e0683c666d0fac41f0c91420c62f8d509273b — Tigran Soghbatyan 4 years ago 2a2d519
[BH-1219] Fix language numeral form

Add support for genitive form for Polish language "minute" word
M image/assets/lang/Polski.json => image/assets/lang/Polski.json +1 -0
@@ 75,6 75,7 @@
  "common_accept": "AKCEPTUJ",
  "common_minute_lower": "minuta",
  "common_minutes_lower": "minuty",
  "common_minutes_lower_genitive": "minut",
  "common_minute_short": "min",
  "common_paused": "Pauza",
  "common_text_copy": "Kopiuj tekst",

M products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationStyle.hpp => products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationStyle.hpp +1 -6
@@ 35,12 35,7 @@ namespace app::meditationStyle
            constexpr inline auto font = style::window::font::largelight;
        } // namespace minute

        namespace list
        {
            constexpr inline auto timeUnitSingular = "common_minute_lower";
            constexpr inline auto timeUnitPlural   = "common_minutes_lower";
        } // namespace list
    }     // namespace icStyle
    } // namespace icStyle

    namespace mrStyle
    {

M products/BellHybrid/apps/application-bell-powernap/data/PowerNapListItem.cpp => products/BellHybrid/apps/application-bell-powernap/data/PowerNapListItem.cpp +3 -10
@@ 5,19 5,12 @@
#include <i18n/i18n.hpp>
#include "data/PowerNapStyle.hpp"

#include <common/LanguageUtils.hpp>
namespace
{
    inline constexpr auto spinnerMax  = 180U;
    inline constexpr auto spinnerMin  = 1U;
    inline constexpr auto spinnerStep = 1U;

    std::string getTimeUnitName(int currentSpinnerValue)
    {
        using namespace gui::powerNapStyle::listItem;
        const auto isSingular = currentSpinnerValue == 1;
        return utils::translate(isSingular ? timeUnitSingular : timeUnitPlural);
    }

} // namespace
namespace gui
{


@@ 72,7 65,7 @@ namespace gui

        inputCallback = [&](Item &, const InputEvent &inputEvent) -> bool {
            if (body->onInput(inputEvent)) {
                setBottomDescribtionText(getTimeUnitName(spinner->getCurrentValue()));
                setBottomDescribtionText(utils::language::getCorrectMinutesNumeralForm(spinner->getCurrentValue()));
                return true;
            }
            return false;


@@ 87,7 80,7 @@ namespace gui
    void PowerNapListItem::setSpinnerValue(int value)
    {
        spinner->setCurrentValue(value);
        setBottomDescribtionText(getTimeUnitName(spinner->getCurrentValue()));
        setBottomDescribtionText(utils::language::getCorrectMinutesNumeralForm(spinner->getCurrentValue()));
        onValueChanged(value);
    }


M products/BellHybrid/apps/application-bell-powernap/data/PowerNapStyle.hpp => products/BellHybrid/apps/application-bell-powernap/data/PowerNapStyle.hpp +0 -5
@@ 11,11 11,6 @@ namespace gui::powerNapStyle
    inline constexpr auto napTimerFont    = style::window::font::verybig;
    inline constexpr auto napPeriodFont   = style::window::font::supersizeme;
    inline constexpr auto clockFont       = style::window::font::verybiglight;
    namespace listItem
    {
        inline constexpr auto timeUnitSingular = "common_minute_lower";
        inline constexpr auto timeUnitPlural   = "common_minutes_lower";
    } // namespace listItem

    namespace progress
    {

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp +6 -10
@@ 3,6 3,7 @@

#include "SnoozeListItemProvider.hpp"
#include <common/widgets/ListItems.hpp>
#include <common/LanguageUtils.hpp>

#include <apps-common/ApplicationCommon.hpp>
#include <utility>


@@ 72,21 73,16 @@ namespace app::bell_settings
        constexpr auto snoozeLengthMin  = 1U;
        constexpr auto snoozeLengthMax  = 30U;

        auto chimeLengthBottomDescription = model.getSnoozeLength().getValue() > 1
                                                ? utils::translate("common_minutes_lower")
                                                : utils::translate("common_minute_lower");
        auto chimeLength                  = new NumListItem(model.getSnoozeLength(),
        auto chimeLengthBottomDescription =
            utils::language::getCorrectMinutesNumeralForm(model.getSnoozeLength().getValue());
        ;
        auto chimeLength = new NumListItem(model.getSnoozeLength(),
                                           UIntegerSpinner::Range{snoozeLengthMin, snoozeLengthMax, snoozeLengthStep},
                                           utils::translate("app_bell_settings_alarm_settings_snooze_length"),
                                           chimeLengthBottomDescription);

        chimeLength->setOnValueChanged([chimeLength](const std::uint32_t &val) {
            if (val == 1) {
                chimeLength->setBottomDescribtionText(utils::translate("common_minute_lower"));
            }
            else {
                chimeLength->setBottomDescribtionText(utils::translate("common_minutes_lower"));
            }
            chimeLength->setBottomDescribtionText(utils::language::getCorrectMinutesNumeralForm(val));
        });

        chimeLength->onEnter = [onOff, this]() {

M products/BellHybrid/apps/common/CMakeLists.txt => products/BellHybrid/apps/common/CMakeLists.txt +2 -0
@@ 13,6 13,7 @@ target_sources(application-bell-common
        src/BellPowerOffPresenter.cpp
        src/AlarmModel.cpp
        src/AudioModel.cpp
        src/LanguageUtils.cpp
        src/TimeModel.cpp
        src/SoundsRepository.cpp
        src/BellListItemProvider.cpp


@@ 42,6 43,7 @@ target_sources(application-bell-common
    PUBLIC
        include/common/Languages.hpp
        include/common/BellListItemProvider.hpp
        include/common/LanguageUtils.hpp
        include/common/SoundsRepository.hpp
        include/common/BellPowerOffPresenter.hpp
        include/common/windows/BellFactoryReset.hpp

A products/BellHybrid/apps/common/include/common/LanguageUtils.hpp => products/BellHybrid/apps/common/include/common/LanguageUtils.hpp +11 -0
@@ 0,0 1,11 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <string>

namespace utils::language
{
    auto getCorrectMinutesNumeralForm(int val) -> std::string;
} // namespace utils::language

A products/BellHybrid/apps/common/src/LanguageUtils.cpp => products/BellHybrid/apps/common/src/LanguageUtils.cpp +23 -0
@@ 0,0 1,23 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <i18n/i18n.hpp>

namespace utils::language
{
    auto getCorrectMinutesNumeralForm(int val) -> std::string
    {
        if (val == 1) {
            return utils::translate("common_minute_lower");
        }
        if (utils::getDisplayLanguage() == "Polski") {
            if (val < 10 || val > 20) {
                if ((val % 10) == 2 || (val % 10) == 3 || (val % 10) == 4) {
                    return utils::translate("common_minutes_lower");
                }
            }
            return utils::translate("common_minutes_lower_genitive");
        }
        return utils::translate("common_minutes_lower");
    }
} // namespace utils::language