LCOV - code coverage report
Current view: top level - muse/framework/global - translation.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 65.4 % 26 17
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #include "translation.h"
      23              : 
      24              : #ifndef NO_QT_SUPPORT
      25              : #include <QCoreApplication>
      26              : #include <QString>
      27              : #endif
      28              : 
      29              : #include "types/bytearray.h"
      30              : #include "types/string.h"
      31              : 
      32              : #include "log.h"
      33              : 
      34              : using namespace muse;
      35              : 
      36        49447 : static String translate(const char* context, const char* key, const char* disambiguation, int n)
      37              : {
      38              : #ifndef NO_QT_SUPPORT
      39        49447 :     return String::fromQString(QCoreApplication::translate(context, key, disambiguation, n));
      40              : #else
      41              :     UNUSED(context);
      42              :     UNUSED(disambiguation);
      43              :     UNUSED(n);
      44              :     return String::fromUtf8(key);
      45              : #endif
      46              : }
      47              : 
      48         3220 : std::string muse::trc(const char* context, const char* key, const char* disambiguation, int n)
      49              : {
      50         3220 :     return translate(context, key, disambiguation, n).toStdString();
      51              : }
      52              : 
      53              : #ifndef NO_QT_SUPPORT
      54          247 : QString muse::qtrc(const char* context, const char* key, const char* disambiguation, int n)
      55              : {
      56          247 :     return QCoreApplication::translate(context, key, disambiguation, n);
      57              : }
      58              : 
      59            0 : QString muse::qtrc(const char* context, const String& key, const char* disambiguation, int n)
      60              : {
      61            0 :     ByteArray utf8 = key.toUtf8();
      62            0 :     return QCoreApplication::translate(context, utf8.constChar(), disambiguation, n);
      63            0 : }
      64              : 
      65            0 : QString muse::qtrc(const char* context, const String& key, const String& disambiguation, int n)
      66              : {
      67            0 :     ByteArray keyutf8 = key.toUtf8();
      68            0 :     ByteArray disutf8 = disambiguation.toUtf8();
      69            0 :     return QCoreApplication::translate(context, keyutf8.constChar(), disutf8.empty() ? nullptr : disutf8.constChar(), n);
      70            0 : }
      71              : 
      72              : #endif
      73              : 
      74         2377 : String muse::mtrc(const char* context, const char* key, const char* disambiguation, int n)
      75              : {
      76         2377 :     return translate(context, key, disambiguation, n);
      77              : }
      78              : 
      79         2346 : String muse::mtrc(const char* context, const String& key, const char* disambiguation, int n)
      80              : {
      81         2346 :     ByteArray keyutf8 = key.toUtf8();
      82         4692 :     return translate(context, keyutf8.constChar(), disambiguation, n);
      83         2346 : }
      84              : 
      85        41504 : String muse::mtrc(const char* context, const String& key, const String& disambiguation, int n)
      86              : {
      87        41504 :     ByteArray keyutf8 = key.toUtf8();
      88        41504 :     ByteArray disutf8 = disambiguation.toUtf8();
      89        83008 :     return translate(context, keyutf8.constChar(), disutf8.empty() ? nullptr : disutf8.constChar(), n);
      90        41504 : }
        

Generated by: LCOV version 2.0-1