blob: bc7e99bf433341374baae0e25ae8dff8710b46b1 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_LIB_INTL_INTL_PROPERTY_PROVIDER_IMPL_LOCALE_UTIL_H_
#define SRC_LIB_INTL_INTL_PROPERTY_PROVIDER_IMPL_LOCALE_UTIL_H_
#include <fuchsia/intl/cpp/fidl.h>
#include <lib/fpromise/result.h>
#include <string>
#include "src/lib/intl/intl_property_provider_impl/icu_headers.h"
namespace intl {
struct LocaleKeys {
static const std::string kCalendar;
static const std::string kFirstDayOfWeek;
static const std::string kHourCycle;
static const std::string kMeasurementSystem;
static const std::string kNumbers;
static const std::string kTimeZone;
};
// Convert the given locale ID to an `icu::Locale`.
fpromise::result<icu::Locale, zx_status_t> LocaleIdToIcuLocale(
const fuchsia::intl::LocaleId& locale_id,
const std::map<std::string, std::string>& unicode_extensions = {});
// Convert the given locale ID to an `icu::Locale`.
//
// Parameters:
// locale_id: A Unicode BCP-47 Locale ID
// unicode_extensions: Optional Unicode extension keys and values to add to
// the locale.
fpromise::result<icu::Locale, zx_status_t> LocaleIdToIcuLocale(
const std::string& locale_id,
const std::map<std::string, std::string>& unicode_extensions = {});
// For the given `icu::Locale`, generate a Unicode BCP-47 Locale ID that
// includes extension keys and values for supported Unicode extensions.
fpromise::result<fuchsia::intl::LocaleId, zx_status_t> ExpandLocaleId(
const icu::Locale& icu_locale);
// Extract just the calendar value from a `CalendarId`, which is of the form
// `"und-u-ca-<calendarid>"`.
fpromise::result<std::string, zx_status_t> ExtractBcp47CalendarId(
const fuchsia::intl::CalendarId& calendar_id);
// Get a Unicode locale ID extension value ("sun", "mon", "tue", etc.) for the
// given day of the week. Used for "First day of week" extension in locale IDs.
//
// See
// https://github.com/unicode-org/cldr/blob/HEAD/common/bcp47/calendar.xml.
std::string ToDayOfWeekString(UCalendarDaysOfWeek day_of_week);
} // namespace intl
#endif // SRC_LIB_INTL_INTL_PROPERTY_PROVIDER_IMPL_LOCALE_UTIL_H_