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 "StelTranslator.hpp" 24 #include "StelCore.hpp" 25 26 //! @class StelLocaleMgr 27 //! Manage i18n operations such as message translation and date/time localization. 28 //! @author Fabien Chereau 29 class StelLocaleMgr 30 { 31 public: 32 StelLocaleMgr(); 33 ~StelLocaleMgr(); 34 35 //! Initialize object. This process includes: 36 //! - Setting the sky and application languages 37 //! - Setting the time and date formats 38 //! - Setting up the time zone 39 void init(); 40 41 /////////////////////////////////////////////////////////////////////////// 42 // MESSAGES TRANSLATIONS 43 /////////////////////////////////////////////////////////////////////////// 44 //! Get the application language currently used for GUI etc. 45 //! This function has no permanent effect on the global locale. 46 //! @return the abbreviated name of the language (e.g "fr"). getAppLanguage() const47 QString getAppLanguage() const { return StelTranslator::globalTranslator->getTrueLocaleName(); } 48 49 //! Set the application language. 50 //! This applies to GUI etc. This function has no permanent effect on the global locale. 51 //! @param newAppLangName the abbreviated name of the language (e.g fr). 52 void setAppLanguage(const QString& newAppLangName, bool refreshAll=true); 53 54 //! Get the StelTranslator object currently used for global application. 55 const StelTranslator& getAppStelTranslator() const; 56 57 //! Get the type (RTL or LTR) of application language currently used for GUI etc. 58 bool isAppRTL() const; 59 60 //! Get the language currently used for sky objects. 61 //! This function has no permanent effect on the global locale. 62 //! @return the name of the language (e.g fr). 63 QString getSkyLanguage() const; 64 65 //! Set the sky language and reload the sky object names with the new 66 //! translation. This function has no permanent effect on the global locale. 67 //! @param newSkyLangName The abbreviated name of the locale (e.g fr) to use 68 //! for sky object labels. 69 void setSkyLanguage(const QString& newSkyLangName, bool refreshAll=true); 70 71 //! Get a reference to the StelTranslator object currently used for sky objects. 72 const StelTranslator &getSkyTranslator() const; 73 74 //! Get a reference to the StelTranslator object currently used for planetary features. 75 const StelTranslator &getPlanetaryFeaturesTranslator() const; 76 77 //! Get a reference to the StelTranslator object currently used for scripts. 78 const StelTranslator &getScriptsTranslator() const; 79 80 //! Get the type (RTL or LTR) of language currently used for sky objects 81 bool isSkyRTL() const; 82 83 /////////////////////////////////////////////////////////////////////////// 84 // DATE & TIME LOCALIZATION 85 /////////////////////////////////////////////////////////////////////////// 86 //! Get the format string which describes the current time format. 87 //! Valid values are: 88 //! - "system_default" 89 //! - "24h" 90 //! - "12h" 91 //! 92 //! These values correspond to the similarly named values in the STimeFormat enum. getTimeFormatStr(void) const93 QString getTimeFormatStr(void) const {return sTimeFormatToString(timeFormat);} 94 //! Set the time format from a format string. 95 //! @param tf values are the same as the return values for getTimeFormatStr(). setTimeFormatStr(const QString & tf)96 void setTimeFormatStr(const QString& tf) {timeFormat=stringToSTimeFormat(tf);} 97 //! Get the format string which describes the current date format. 98 //! Valid values: 99 //! - "mmddyyyy" 100 //! - "ddmmyyyy" 101 //! - "system_default" 102 //! - "yyyymmdd" 103 //! 104 //! These values correspond to the similarly named values in the SDateFormat enum. getDateFormatStr(void) const105 QString getDateFormatStr(void) const {return sDateFormatToString(dateFormat);} setDateFormatStr(const QString & df)106 void setDateFormatStr(const QString& df) {dateFormat=stringToSDateFormat(df);} 107 108 //! Get the format string which describes the current date format (Qt style). 109 QString getQtDateFormatStr(void) const; 110 111 //! @enum STimeFormat 112 //! The time display format. 113 enum STimeFormat { 114 STimeSystemDefault, //!< use the system default format. 115 STime24h, //!< 24 hour clock, e.g. "18:22:00" 116 STime12h //!< 12 hour clock, e.g. "06:22:00 pm" 117 }; 118 119 //! @enum SDateFormat 120 //! The date display format. 121 enum SDateFormat { 122 SDateSystemDefault, //!< Use the system default date format 123 SDateMMDDYYYY, //!< e.g. "07-05-1998" for July 5th 1998 124 SDateDDMMYYYY, //!< e.g. "05-07-1998" for July 5th 1998 125 SDateYYYYMMDD, //!< e.g. "1998-07-05" for July 5th 1998 126 SDateWWMMDDYYYY, //!< e.g. "Sun, 07-05-1998" for Sunday, July 5th 1998 127 SDateWWDDMMYYYY, //!< e.g. "Sun, 05-07-1998" for Sunday, July 5th 1998 128 SDateWWYYYYMMDD //!< e.g. "Sun, 1998-07-05" for Sunday, July 5th 1998 129 }; 130 131 //! Get a localized, formatted string representation of the date component of a Julian date. 132 QString getPrintableDateLocal(double JD) const; 133 134 //! Get a localized, formatted string representation of the time component of a Julian date. 135 QString getPrintableTimeLocal(double JD) const; 136 137 //! Get a localized, formatted string representation of the time zone of a Julian date. 138 QString getPrintableTimeZoneLocal(double JD) const; 139 140 //! Return the time in ISO 8601 format that is : %Y-%m-%dT%H:%M:%S 141 //! @param JD the time and date expressed as a Julian date value. 142 QString getISO8601TimeLocal(double JD) const; 143 144 //! Return the JD time for a local time ISO 8601 format that is: 145 //! %Y-%m-%dT%H:%M:%S, but %Y can be a large number with sign, and 146 //! %Y can be zero. 147 //! @param str the local time in ISO 8601 format. 148 //! @param ok set to false if the string was an invalid date. 149 double getJdFromISO8601TimeLocal(const QString& str, bool* ok) const; 150 151 //! Returns the short name of the \a weekday [0=Sunday, 1=Monday..6]; weekday mod 7) 152 static QString shortDayName(int weekday); 153 154 //! Returns the long name of the \a weekday ([0..6]; weekday mod 7) 155 static QString longDayName(int weekday); 156 157 //! Returns the short name of the \a month [1..12] 158 static QString shortMonthName(int month); 159 160 //! Returns the long name of the \a month [1..12] 161 static QString longMonthName(int month); 162 163 //! Returns the genitive long name of the \a month [1..12] 164 static QString longGenitiveMonthName(int month); 165 166 //! Returns the Roman name (a number) of the \a month [1..12] 167 static QString romanMonthName(int month); 168 169 private: 170 //! fill the class-inherent lists with translated names for weekdays, month names etc. in the current language. 171 //! Call this at program start and then after each language change. 172 static void createNameLists(); 173 // The translator used for astronomical object naming 174 StelTranslator* skyTranslator; 175 StelTranslator* planetaryFeaturesTranslator; 176 StelTranslator* scriptsTranslator; 177 StelCore* core; 178 179 // Date and time variables 180 STimeFormat timeFormat; 181 SDateFormat dateFormat; 182 183 // Convert the time format enum to its associated string and reverse 184 static STimeFormat stringToSTimeFormat(const QString&); 185 static QString sTimeFormatToString(STimeFormat); 186 187 // Convert the date format enum to its associated string and reverse 188 static SDateFormat stringToSDateFormat(const QString& df); 189 static QString sDateFormatToString(SDateFormat df); 190 191 // Lists for rapid access. These must be recreated on language change by createNameLists(). 192 static QStringList shortWeekDays; 193 static QStringList longWeekDays; 194 static QStringList shortMonthNames; 195 static QStringList longMonthNames; 196 static QStringList longGenitiveMonthNames; 197 }; 198 199 #endif // STELLOCALEMGR_HPP 200