• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ParadoxGameConverters / commonItems / 12474699231

24 Dec 2024 12:16AM UTC coverage: 59.712% (-0.9%) from 60.619%
12474699231

Pull #272

github

web-flow
Merge eff7dcf9d into f5b02f298
Pull Request #272: Create a cmake target for the commons library

1 of 1 new or added line in 1 file covered. (100.0%)

34 existing lines in 7 files now uncovered.

2198 of 3681 relevant lines covered (59.71%)

177.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Localization/LocalizationBlock.h
1
#ifndef LOCALIZATION_LOCALIZATION_BLOCK_H
2
#define LOCALIZATION_LOCALIZATION_BLOCK_H
3

4

5

6
#include "LocalizationLambdas.h"
7
#include <map>
8
#include <optional>
9
#include <string>
10

11

12

13
namespace commonItems
14
{
15

16
class LocalizationBlock
17
{
18
  public:
UNCOV
19
        LocalizationBlock(std::string key, std::string base_language): key_(std::move(key)), base_language_(std::move(base_language)) {}
×
20
        LocalizationBlock(std::string key, const LocalizationBlock& other_block):
21
                 key_(std::move(key)), languages_to_localizations_(other_block.languages_to_localizations_), base_language_(other_block.base_language_)
22
        {
23
        }
24
        void CopyFrom(const LocalizationBlock& other_block);
25

26
        [[nodiscard]] const std::string& GetKey() const { return key_; }
27
        [[nodiscard]] const std::string& GetBaseLanguage() const { return base_language_; }
UNCOV
28
        [[nodiscard]] const std::map<std::string, std::string>& GetLocalizations() const { return languages_to_localizations_; }
×
29

30
        [[nodiscard]] std::string GetLocalization(const std::string& language) const;
31

UNCOV
32
        void ModifyLocalization(const std::string& language, const std::string& localization) { languages_to_localizations_[language] = localization; }
×
33

34
        // ModifyForEveryLanguage helps remove boilerplate by applying modifying_function to every language in the block
35
        // For example:
36
        //  name_block["english"] = name_block["english"].replace("$ADJ$", base_adjective_block.GetLocalization("english"));
37
        //  name_block["french"] = name_block["french"].replace("$ADJ$", base_adjective_block.GetLocalization("french"));
38
        //  name_block["german"] = name_block["german"].replace("$ADJ$", base_adjective_block.GetLocalization("german"));
39
        //  name_block["russian"] = name_block["russian"].replace("$ADJ$", base_adjective_block.GetLocalization("russian"));
40
        //  name_block["simp_chinese"] = name_block["simp_chinese"].replace("$ADJ$", base_adjective_block.GetLocalization("simp_chinese"));
41
        //  name_block["spanish"] = name_block["spanish"].replace("$ADJ$", base_adjective_block.GetLocalization("spanish"));
42
        //
43
        // Can be replaced by:
44
        // name_block.ModifyForEveryLanguage(adjective_block,
45
        //         [](const std::string& base_localization, const std::string& modifying_localization, const std::string& language) {
46
        //                const std::string placeholder = "$ADJ$";
47
        //                std::string updated_localization = base_localization;
48
        //                return updated_localization.replace(updated_localization.find(placeholder), placeholder.size(), modifying_localization);
49
        // });
50
        void ModifyForEveryLanguage(const LocalizationLambda& modifying_function);
51
        void ModifyForEveryLanguage(const LocalizationBlock& other_block, const TwoArgLocalizationLambda& modifying_function);
52

53
  private:
54
        std::string key_;
55
        std::map<std::string, std::string> languages_to_localizations_;
56
        std::string base_language_;
57
};
58

59
} // namespace commonItems
60

61

62

63
#endif // LOCALIZATION_LOCALIZATION_BLOCK_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc