mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Pass scriptcode and variantcode to dart:ui Window. (#6493)
This commit is contained in:
parent
0eda0cfd41
commit
61cf4c01fd
@ -48,7 +48,7 @@ String _localeClosure() => window._locale.toString();
|
||||
_LocaleClosure _getLocaleClosure() => _localeClosure;
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void _updateLocale(String languageCode, String countryCode) {
|
||||
void _updateLocale(String languageCode, String countryCode, String scriptCode, String variantCode) {
|
||||
window._locale = new Locale(languageCode, countryCode);
|
||||
_invoke(window.onLocaleChanged, window._onLocaleChangedZone);
|
||||
}
|
||||
|
||||
@ -163,7 +163,9 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) {
|
||||
}
|
||||
|
||||
void Window::UpdateLocale(const std::string& language_code,
|
||||
const std::string& country_code) {
|
||||
const std::string& country_code,
|
||||
const std::string& script_code,
|
||||
const std::string& variant_code) {
|
||||
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
|
||||
if (!dart_state)
|
||||
return;
|
||||
@ -173,6 +175,8 @@ void Window::UpdateLocale(const std::string& language_code,
|
||||
{
|
||||
StdStringToDart(language_code),
|
||||
StdStringToDart(country_code),
|
||||
StdStringToDart(script_code),
|
||||
StdStringToDart(variant_code),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +60,9 @@ class Window final {
|
||||
void DidCreateIsolate();
|
||||
void UpdateWindowMetrics(const ViewportMetrics& metrics);
|
||||
void UpdateLocale(const std::string& language_code,
|
||||
const std::string& country_code);
|
||||
const std::string& country_code,
|
||||
const std::string& script_code,
|
||||
const std::string& variant_code);
|
||||
void UpdateUserSettingsData(const std::string& data);
|
||||
void UpdateSemanticsEnabled(bool enabled);
|
||||
void UpdateAccessibilityFeatures(int32_t flags);
|
||||
|
||||
@ -124,7 +124,8 @@ std::unique_ptr<RuntimeController> RuntimeController::Clone() const {
|
||||
|
||||
bool RuntimeController::FlushRuntimeStateToIsolate() {
|
||||
return SetViewportMetrics(window_data_.viewport_metrics) &&
|
||||
SetLocale(window_data_.language_code, window_data_.country_code) &&
|
||||
SetLocale(window_data_.language_code, window_data_.country_code,
|
||||
window_data_.script_code, window_data_.variant_code) &&
|
||||
SetSemanticsEnabled(window_data_.semantics_enabled) &&
|
||||
SetAccessibilityFeatures(window_data_.accessibility_feature_flags_);
|
||||
}
|
||||
@ -140,12 +141,17 @@ bool RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) {
|
||||
}
|
||||
|
||||
bool RuntimeController::SetLocale(const std::string& language_code,
|
||||
const std::string& country_code) {
|
||||
const std::string& country_code,
|
||||
const std::string& script_code,
|
||||
const std::string& variant_code) {
|
||||
window_data_.language_code = language_code;
|
||||
window_data_.country_code = country_code;
|
||||
window_data_.script_code = script_code;
|
||||
window_data_.variant_code = variant_code;
|
||||
|
||||
if (auto window = GetWindowIfAvailable()) {
|
||||
window->UpdateLocale(window_data_.language_code, window_data_.country_code);
|
||||
window->UpdateLocale(window_data_.language_code, window_data_.country_code,
|
||||
window_data_.script_code, window_data_.variant_code);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +41,9 @@ class RuntimeController final : public WindowClient {
|
||||
bool SetViewportMetrics(const ViewportMetrics& metrics);
|
||||
|
||||
bool SetLocale(const std::string& language_code,
|
||||
const std::string& country_code);
|
||||
const std::string& country_code,
|
||||
const std::string& script_code,
|
||||
const std::string& variant_code);
|
||||
|
||||
bool SetUserSettingsData(const std::string& data);
|
||||
|
||||
@ -80,6 +82,8 @@ class RuntimeController final : public WindowClient {
|
||||
ViewportMetrics viewport_metrics;
|
||||
std::string language_code;
|
||||
std::string country_code;
|
||||
std::string script_code;
|
||||
std::string variant_code;
|
||||
std::string user_settings_data = "{}";
|
||||
bool semantics_enabled = false;
|
||||
bool assistive_technology_enabled = false;
|
||||
|
||||
@ -327,12 +327,15 @@ bool Engine::HandleLocalizationPlatformMessage(
|
||||
|
||||
const auto& language = args->value[0];
|
||||
const auto& country = args->value[1];
|
||||
const auto& script = args->value[2];
|
||||
const auto& variant = args->value[3];
|
||||
|
||||
if (!language.IsString() || !country.IsString())
|
||||
return false;
|
||||
|
||||
return runtime_controller_->SetLocale(language.GetString(),
|
||||
country.GetString());
|
||||
country.GetString(), script.GetString(),
|
||||
variant.GetString());
|
||||
}
|
||||
|
||||
void Engine::HandleSettingsPlatformMessage(blink::PlatformMessage* message) {
|
||||
|
||||
@ -317,7 +317,7 @@ public class FlutterView extends SurfaceView
|
||||
}
|
||||
|
||||
private void setLocale(Locale locale) {
|
||||
mFlutterLocalizationChannel.invokeMethod("setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry()));
|
||||
mFlutterLocalizationChannel.invokeMethod("setLocale", Arrays.asList(locale.getLanguage(), locale.getCountry(), locale.getScript(), locale.getVariant()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -894,8 +894,16 @@ static blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) {
|
||||
NSLocale* currentLocale = [NSLocale currentLocale];
|
||||
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];
|
||||
NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
|
||||
NSString* scriptCode = [currentLocale objectForKey:NSLocaleScriptCode];
|
||||
NSString* variantCode = [currentLocale objectForKey:NSLocaleVariantCode];
|
||||
if (languageCode && countryCode)
|
||||
[_localizationChannel.get() invokeMethod:@"setLocale" arguments:@[ languageCode, countryCode ]];
|
||||
// We pass empty strings for undefined scripts and variants to ensure the JSON encoder/decoder
|
||||
// functions properly.
|
||||
[_localizationChannel.get() invokeMethod:@"setLocale"
|
||||
arguments:@[
|
||||
languageCode, countryCode, scriptCode ? scriptCode : @"",
|
||||
variantCode ? variantCode : @""
|
||||
]];
|
||||
}
|
||||
|
||||
#pragma mark - Set user settings
|
||||
|
||||
@ -100,7 +100,7 @@ void main() {
|
||||
};
|
||||
});
|
||||
|
||||
_updateLocale('en', 'US');
|
||||
_updateLocale('en', 'US', '', '');
|
||||
expect(runZone, isNotNull);
|
||||
expect(runZone, same(innerZone));
|
||||
expect(locale, equals(const Locale('en', 'US')));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user