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

Stellarium / stellarium / 17068063291

19 Aug 2025 11:22AM UTC coverage: 11.766%. Remained the same
17068063291

push

github

alex-w
Reformatting

14706 of 124990 relevant lines covered (11.77%)

18303.49 hits per line

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

0.0
/src/core/StelLocaleMgr.hpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2006 Fabien Chereau
4
 * 
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 * 
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 * 
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
18
 */
19

20
#ifndef STELLOCALEMGR_HPP
21
#define STELLOCALEMGR_HPP
22

23
#include <memory>
24
#include "StelTranslator.hpp"
25
#include "StelCore.hpp"
26

27
//! @class StelLocaleMgr
28
//! Manage i18n operations such as message translation and date/time localization.
29
//! @author Fabien Chereau
30
class StelLocaleMgr
31
{
32
public:
33
        StelLocaleMgr();
34
        ~StelLocaleMgr();
35

36
        //! Initialize object. This process includes:
37
        //! - Setting the sky and application languages
38
        //! - Setting the time and date formats
39
        //! - Setting up the time zone
40
        void init();
41
        
42
        ///////////////////////////////////////////////////////////////////////////
43
        // MESSAGES TRANSLATIONS
44
        ///////////////////////////////////////////////////////////////////////////
45
        //! Get the application language currently used for GUI etc.
46
        //! This function has no permanent effect on the global locale.
47
        //! @return the abbreviated name of the language (e.g "fr").
48
        QString getAppLanguage() const { return StelTranslator::globalTranslator->getTrueLocaleName(); }
×
49
        
50
        //! Set the application language. 
51
        //! This applies to GUI etc. This function has no permanent effect on the global locale.
52
        //! @param newAppLangName the abbreviated name of the language (e.g fr).
53
        void setAppLanguage(const QString& newAppLangName, bool refreshAll=true);
54
        
55
        //! Get the StelTranslator object currently used for global application.
56
        const StelTranslator& getAppStelTranslator() const;
57

58
        //! Get the type (RTL or LTR) of application language currently used for GUI etc.
59
        bool isAppRTL() const;
60
        
61
        //! Get the language currently used for sky objects.
62
        //! This function has no permanent effect on the global locale.
63
        //! @return the name of the language (e.g fr).
64
        QString getSkyLanguage() const;
65
        
66
        //! Get a reference to the StelTranslator object currently used for sky objects.
67
        const StelTranslator &getSkyTranslator() const;
68

69
        //! Get a reference to the StelTranslator object currently used for planetary features.
70
        const StelTranslator &getPlanetaryFeaturesTranslator() const;
71

72
        //! Get a reference to the StelTranslator object currently used for scripts.
73
        const StelTranslator &getScriptsTranslator() const;
74

75
        //! Get a reference to the StelTranslator object currently used for sky cultures descriptions.
76
        const StelTranslator &getSkyCultureDescriptionsTranslator() const;
77

78
        //! Get the type (RTL or LTR) of language currently used for sky objects
79
        bool isSkyRTL() const;
80
        
81
        ///////////////////////////////////////////////////////////////////////////
82
        // DATE & TIME LOCALIZATION
83
        ///////////////////////////////////////////////////////////////////////////
84
        //! Get the format string which describes the current time format.
85
        //! Valid values are:
86
        //! - "system_default"
87
        //! - "24h"
88
        //! - "12h"
89
        //!
90
        //! These values correspond to the similarly named values in the STimeFormat enum.
91
        QString getTimeFormatStr(void) const {return sTimeFormatToString(timeFormat);}
×
92
        //! Set the time format from a format string.
93
        //! @param tf values are the same as the return values for getTimeFormatStr().
94
        void setTimeFormatStr(const QString& tf) {timeFormat=stringToSTimeFormat(tf);}
×
95
        //! Get the format string which describes the current date format.
96
        //! Valid values:
97
        //! - "mmddyyyy"
98
        //! - "ddmmyyyy"
99
        //! - "system_default"
100
        //! - "yyyymmdd"
101
        //!
102
        //! These values correspond to the similarly named values in the SDateFormat enum.
103
        QString getDateFormatStr(void) const {return sDateFormatToString(dateFormat);}        
×
104
        void setDateFormatStr(const QString& df) {dateFormat=stringToSDateFormat(df);}
×
105

106
        //! Get the format string which describes the current date format (Qt style).
107
        QString getQtDateFormatStr(void) const;
108
        
109
        //! @enum STimeFormat
110
        //! The time display format.
111
        enum STimeFormat {
112
                STimeSystemDefault,        //!< use the system default format.
113
                STime24h,                //!< 24 hour clock, e.g. "18:22:00"
114
                STime12h                //!< 12 hour clock, e.g. "06:22:00 pm"
115
        };
116
        
117
        //! @enum SDateFormat
118
        //! The date display format.
119
        enum SDateFormat {
120
                SDateSystemDefault,        //!< Use the system default date format
121
                SDateMMDDYYYY,                //!< e.g. "07-05-1998" for July 5th 1998
122
                SDateDDMMYYYY,                //!< e.g. "05-07-1998" for July 5th 1998
123
                SDateYYYYMMDD,                //!< e.g. "1998-07-05" for July 5th 1998
124
                SDateWWMMDDYYYY,        //!< e.g. "Sun, 07-05-1998" for Sunday, July 5th 1998
125
                SDateWWDDMMYYYY,        //!< e.g. "Sun, 05-07-1998" for Sunday, July 5th 1998
126
                SDateWWYYYYMMDD                //!< e.g. "Sun, 1998-07-05" for Sunday, July 5th 1998
127
        };
128
        
129
        //! Get a localized, formatted string representation of the date component of a Julian date.
130
        //! @param utcOffsetHrs from StelCore::getUTCOffset(JD)
131
        QString getPrintableDateLocal(double JD, double utcOffsetHrs) const;
132
        
133
        //! Get a localized, formatted string representation of the time component of a Julian date.
134
        //! @param utcOffsetHrs from StelCore::getUTCOffset(JD)
135
        QString getPrintableTimeLocal(double JD, double utcOffsetHrs) const;
136

137
        //! Get a localized, formatted string representation of the time zone of a Julian date.
138
        //! @param utcOffsetHrs from StelCore::getUTCOffset(JD)
139
        QString getPrintableTimeZoneLocal(double JD, double utcOffsetHrs) const;
140

141
        //! Return the time in ISO 8601 format that is : %Y-%m-%dT%H:%M:%S
142
        //! @param JD the time and date expressed as a Julian date value.
143
        //! @param utcOffsetHrs from StelCore::getUTCOffset(JD)
144
        QString getISO8601TimeLocal(double JD, double utcOffsetHrs) const;
145

146
        //! Return the JD time for a local time ISO 8601 format that is:
147
        //! %Y-%m-%dT%H:%M:%S, but %Y can be a large number with sign, and
148
        //! %Y can be zero.
149
        //! @param str the local time in ISO 8601 format.
150
        //! @param ok set to false if the string was an invalid date.
151
        double getJdFromISO8601TimeLocal(const QString& str, bool* ok) const;
152

153
        //! Returns the short name of the \a weekday [0=Sunday, 1=Monday..6]; weekday mod 7)
154
        static QString shortDayName(int weekday);
155

156
        //! Returns the long name of the \a weekday ([0..6]; weekday mod 7)
157
        static QString longDayName(int weekday);
158

159
        //! Returns the short name of the \a month [1..12]
160
        static QString shortMonthName(int month);
161

162
        //! Returns the long name of the \a month [1..12]
163
        static QString longMonthName(int month);
164

165
        //! Returns the genitive long name of the \a month [1..12]
166
        static QString longGenitiveMonthName(int month);
167

168
        //! Returns the Roman name (a number) of the \a month [1..12]
169
        static QString romanMonthName(int month);
170
        
171
private:
172
        //! fill the class-inherent lists with translated names for weekdays, month names etc. in the current language.
173
        //! Call this at program start and then after each language change.
174
        static void createNameLists();
175
        // The translator used for astronomical object naming
176
        std::unique_ptr<StelTranslator> skyTranslator;
177
        std::unique_ptr<StelTranslator> planetaryFeaturesTranslator;
178
        std::unique_ptr<StelTranslator> scriptsTranslator;
179
        std::unique_ptr<StelTranslator> skyCultureDescriptionsTranslator;
180
        StelCore* core;
181
        
182
        // Date and time variables
183
        STimeFormat timeFormat;
184
        SDateFormat dateFormat;
185

186
        // Convert the time format enum to its associated string and reverse
187
        static STimeFormat stringToSTimeFormat(const QString&);
188
        static QString sTimeFormatToString(STimeFormat);
189
        
190
        // Convert the date format enum to its associated string and reverse
191
        static SDateFormat stringToSDateFormat(const QString& df);
192
        static QString sDateFormatToString(SDateFormat df);
193
        
194
        // Lists for rapid access. These must be recreated on language change by createNameLists().
195
        static QStringList shortWeekDays;
196
        static QStringList longWeekDays;
197
        static QStringList shortMonthNames;
198
        static QStringList longMonthNames;
199
        static QStringList longGenitiveMonthNames;
200
};
201

202
#endif // STELLOCALEMGR_HPP
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