2014-12-18 18:40:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-12-18 18:40:49 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-12-18 18:40:49 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
#include "lang/lang_instance.h"
|
2017-04-12 19:17:55 +00:00
|
|
|
|
2017-04-13 17:59:05 +00:00
|
|
|
inline QString lang(LangKey key) {
|
|
|
|
return Lang::Current().getValue(key);
|
|
|
|
}
|
2014-12-19 21:20:30 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
inline base::lambda<QString()> langFactory(LangKey key) {
|
|
|
|
return [key] { return Lang::Current().getValue(key); };
|
|
|
|
}
|
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
template <typename WithYear, typename WithoutYear>
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDateMaybeWithYear(QDate date, WithYear withYear, WithoutYear withoutYear) {
|
2017-03-07 14:03:07 +00:00
|
|
|
auto month = date.month();
|
|
|
|
if (month <= 0 || month > 12) {
|
|
|
|
return qsl("MONTH_ERR");
|
|
|
|
};
|
|
|
|
auto year = date.year();
|
|
|
|
auto current = QDate::currentDate();
|
|
|
|
auto currentYear = current.year();
|
|
|
|
auto currentMonth = current.month();
|
|
|
|
if (year != currentYear) {
|
|
|
|
auto yearIsMuchGreater = [](int year, int otherYear) {
|
|
|
|
return (year > otherYear + 1);
|
|
|
|
};
|
|
|
|
auto monthIsMuchGreater = [](int year, int month, int otherYear, int otherMonth) {
|
|
|
|
return (year == otherYear + 1) && (month + 12 > otherMonth + 3);
|
|
|
|
};
|
|
|
|
if (false
|
|
|
|
|| yearIsMuchGreater(year, currentYear)
|
|
|
|
|| yearIsMuchGreater(currentYear, year)
|
|
|
|
|| monthIsMuchGreater(year, month, currentYear, currentMonth)
|
|
|
|
|| monthIsMuchGreater(currentYear, currentMonth, year, month)) {
|
|
|
|
return withYear(month, year);
|
2015-12-21 13:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-07 14:03:07 +00:00
|
|
|
return withoutYear(month, year);
|
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDayOfMonth(const QDate &date) {
|
2017-03-07 14:03:07 +00:00
|
|
|
auto day = date.day();
|
|
|
|
return langDateMaybeWithYear(date, [day](int month, int year) {
|
|
|
|
return lng_month_day_year(lt_month, lang(LangKey(lng_month1_small + month - 1)), lt_day, QString::number(day), lt_year, QString::number(year));
|
|
|
|
}, [day](int month, int year) {
|
|
|
|
return lng_month_day(lt_month, lang(LangKey(lng_month1_small + month - 1)), lt_day, QString::number(day));
|
|
|
|
});
|
2015-12-21 13:14:29 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDayOfMonthFull(const QDate &date) {
|
2017-03-07 14:03:07 +00:00
|
|
|
auto day = date.day();
|
|
|
|
return langDateMaybeWithYear(date, [day](int month, int year) {
|
|
|
|
return lng_month_day_year(lt_month, lang(LangKey(lng_month1 + month - 1)), lt_day, QString::number(day), lt_year, QString::number(year));
|
|
|
|
}, [day](int month, int year) {
|
|
|
|
return lng_month_day(lt_month, lang(LangKey(lng_month1 + month - 1)), lt_day, QString::number(day));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langMonthOfYear(int month, int year) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return (month > 0 && month <= 12) ? lng_month_year(lt_month, lang(LangKey(lng_month1_small + month - 1)), lt_year, QString::number(year)) : qsl("MONTH_ERR");
|
2014-12-18 18:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langMonth(const QDate &date) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return langDateMaybeWithYear(date, [](int month, int year) {
|
|
|
|
return langMonthOfYear(month, year);
|
|
|
|
}, [](int month, int year) {
|
|
|
|
return lang(LangKey(lng_month1_small + month - 1));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langMonthOfYearFull(int month, int year) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return (month > 0 && month <= 12) ? lng_month_year(lt_month, lang(LangKey(lng_month1 + month - 1)), lt_year, QString::number(year)) : qsl("MONTH_ERR");
|
2015-12-22 15:32:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langMonthFull(const QDate &date) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return langDateMaybeWithYear(date, [](int month, int year) {
|
|
|
|
return langMonthOfYearFull(month, year);
|
|
|
|
}, [](int month, int year) {
|
|
|
|
return lang(LangKey(lng_month1 + month - 1));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDayOfWeek(int index) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return (index > 0 && index <= 7) ? lang(LangKey(lng_weekday1 + index - 1)) : qsl("DAY_ERR");
|
2015-12-22 15:32:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDayOfWeek(const QDate &date) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return langDayOfWeek(date.dayOfWeek());
|
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDayOfWeekFull(int index) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return (index > 0 && index <= 7) ? lang(LangKey(lng_weekday1_full + index - 1)) : qsl("DAY_ERR");
|
2014-12-18 18:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDayOfWeekFull(const QDate &date) {
|
2017-03-07 14:03:07 +00:00
|
|
|
return langDayOfWeekFull(date.dayOfWeek());
|
2014-12-18 18:40:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDateTime(const QDateTime &date) {
|
2015-12-21 13:14:29 +00:00
|
|
|
return lng_mediaview_date_time(lt_date, langDayOfMonth(date.date()), lt_time, date.time().toString(cTimeFormat()));
|
|
|
|
}
|
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
inline QString langDateTimeFull(const QDateTime &date) {
|
2015-12-21 13:14:29 +00:00
|
|
|
return lng_mediaview_date_time(lt_date, langDayOfMonthFull(date.date()), lt_time, date.time().toString(cTimeFormat()));
|
|
|
|
}
|
|
|
|
|
2016-05-14 18:14:55 +00:00
|
|
|
QString langNewVersionText();
|
2014-12-18 18:40:49 +00:00
|
|
|
|
2017-04-13 08:45:58 +00:00
|
|
|
bool langFirstNameGoesSecond();
|