Flutter Engine
The Flutter Engine
fuchsia_intl.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "fuchsia_intl.h"
6
7#include <sstream>
8#include <string>
9#include <vector>
10
11#include "rapidjson/document.h"
12#include "rapidjson/stringbuffer.h"
13#include "rapidjson/writer.h"
14#include "runner.h"
16#include "third_party/icu/source/common/unicode/bytestream.h"
17#include "third_party/icu/source/common/unicode/errorcode.h"
18#include "third_party/icu/source/common/unicode/locid.h"
19#include "third_party/icu/source/common/unicode/strenum.h"
20#include "third_party/icu/source/common/unicode/stringpiece.h"
21#include "third_party/icu/source/common/unicode/uloc.h"
22
23using icu::Locale;
24
25namespace flutter_runner {
26
27using fuchsia::intl::Profile;
28
30 const Profile& intl_profile) {
31 rapidjson::Document document;
32 auto& allocator = document.GetAllocator();
33 document.SetObject();
34 document.AddMember("method", "setLocale", allocator);
35 rapidjson::Value args(rapidjson::kArrayType);
36
37 for (const auto& locale_id : intl_profile.locales()) {
38 UErrorCode error_code = U_ZERO_ERROR;
39 icu::Locale locale = icu::Locale::forLanguageTag(locale_id.id, error_code);
40 if (U_FAILURE(error_code)) {
41 FML_LOG(ERROR) << "Error parsing locale ID \"" << locale_id.id << "\"";
42 continue;
43 }
44 args.PushBack(rapidjson::Value().SetString(locale.getLanguage(), allocator),
45 allocator);
46
47 auto country = locale.getCountry() != nullptr ? locale.getCountry() : "";
48 args.PushBack(rapidjson::Value().SetString(country, allocator), allocator);
49
50 auto script = locale.getScript() != nullptr ? locale.getScript() : "";
51 args.PushBack(rapidjson::Value().SetString(script, allocator), allocator);
52
53 std::string variant =
54 locale.getVariant() != nullptr ? locale.getVariant() : "";
55 // ICU4C capitalizes the variant for backward compatibility, even though
56 // the preferred form is lowercase. So we lowercase here.
57 std::transform(begin(variant), end(variant), begin(variant),
58 [](unsigned char c) { return std::tolower(c); });
59 args.PushBack(rapidjson::Value().SetString(variant, allocator), allocator);
60 }
61
62 document.AddMember("args", args, allocator);
63
64 rapidjson::StringBuffer buffer;
65 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
66 document.Accept(writer);
67 auto data = reinterpret_cast<const uint8_t*>(buffer.GetString());
68 return fml::MallocMapping::Copy(data, buffer.GetSize());
69}
70
71} // namespace flutter_runner
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:144
static MallocMapping Copy(const T *begin, const T *end)
Definition: mapping.h:162
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
glong glong end
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
#define FML_LOG(severity)
Definition: logging.h:82
fml::MallocMapping MakeLocalizationPlatformMessageData(const Profile &intl_profile)
Definition: fuchsia_intl.cc:29
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
#define ERROR(message)
Definition: elf_loader.cc:260