LCOV - code coverage report
Current view: top level - src/util - translation.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 23 23 100.0 %
Date: 2022-04-21 14:51:19 Functions: 18 28 64.3 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2019-2021 The Bitcoin Core developers
#       2                 :            : // Distributed under the MIT software license, see the accompanying
#       3                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       4                 :            : 
#       5                 :            : #ifndef BITCOIN_UTIL_TRANSLATION_H
#       6                 :            : #define BITCOIN_UTIL_TRANSLATION_H
#       7                 :            : 
#       8                 :            : #include <tinyformat.h>
#       9                 :            : #include <functional>
#      10                 :            : 
#      11                 :            : /**
#      12                 :            :  * Bilingual messages:
#      13                 :            :  *   - in GUI: user's native language + untranslated (i.e. English)
#      14                 :            :  *   - in log and stderr: untranslated only
#      15                 :            :  */
#      16                 :            : struct bilingual_str {
#      17                 :            :     std::string original;
#      18                 :            :     std::string translated;
#      19                 :            : 
#      20                 :            :     bilingual_str& operator+=(const bilingual_str& rhs)
#      21                 :       1262 :     {
#      22                 :       1262 :         original += rhs.original;
#      23                 :       1262 :         translated += rhs.translated;
#      24                 :       1262 :         return *this;
#      25                 :       1262 :     }
#      26                 :            : 
#      27                 :            :     bool empty() const
#      28                 :       4301 :     {
#      29                 :       4301 :         return original.empty();
#      30                 :       4301 :     }
#      31                 :            : 
#      32                 :            :     void clear()
#      33                 :      22315 :     {
#      34                 :      22315 :         original.clear();
#      35                 :      22315 :         translated.clear();
#      36                 :      22315 :     }
#      37                 :            : };
#      38                 :            : 
#      39                 :            : inline bilingual_str operator+(bilingual_str lhs, const bilingual_str& rhs)
#      40                 :        139 : {
#      41                 :        139 :     lhs += rhs;
#      42                 :        139 :     return lhs;
#      43                 :        139 : }
#      44                 :            : 
#      45                 :            : /** Mark a bilingual_str as untranslated */
#      46                 :      49393 : inline bilingual_str Untranslated(std::string original) { return {original, original}; }
#      47                 :            : 
#      48                 :            : namespace tinyformat {
#      49                 :            : template <typename... Args>
#      50                 :            : bilingual_str format(const bilingual_str& fmt, const Args&... args)
#      51                 :        888 : {
#      52                 :        888 :     return bilingual_str{format(fmt.original, args...), format(fmt.translated, args...)};
#      53                 :        888 : }
#      54                 :            : } // namespace tinyformat
#      55                 :            : 
#      56                 :            : /** Translate a message to the native language of the user. */
#      57                 :            : const extern std::function<std::string(const char*)> G_TRANSLATION_FUN;
#      58                 :            : 
#      59                 :            : /**
#      60                 :            :  * Translation function.
#      61                 :            :  * If no translation function is set, simply return the input.
#      62                 :            :  */
#      63                 :            : inline bilingual_str _(const char* psz)
#      64                 :      13495 : {
#      65         [ -  + ]:      13495 :     return bilingual_str{psz, G_TRANSLATION_FUN ? (G_TRANSLATION_FUN)(psz) : psz};
#      66                 :      13495 : }
#      67                 :            : 
#      68                 :            : #endif // BITCOIN_UTIL_TRANSLATION_H

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a