From 9d39cec9b045f5dd1a59d45f66ecfdbdc0e12ed5 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 3 Aug 2021 16:57:42 +0800 Subject: [PATCH] fix: register local not preferred language issue. resolve #238 --- .../MastodonRegisterViewController.swift | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift index 5ea418e45..ffef3d872 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift @@ -744,13 +744,33 @@ extension MastodonRegisterViewController { let username = viewModel.username.value let email = viewModel.email.value let password = viewModel.password.value + + let locale: String = { + let fallbackLanguageCode = Locale.current.languageCode ?? "en" + guard let identifier = Locale.preferredLanguages.first else { + return fallbackLanguageCode + } + let local = Locale(identifier: identifier) + guard let languageCode = local.languageCode else { + return fallbackLanguageCode + } + switch languageCode { + case "zh": + // Check Simplified Chinese / Traditional Chinese + // https://github.com/gunchleoc/mastodon/blob/ed6153b8f24d3a8f5a124cc95683bd1f20aec882/app/helpers/settings_helper.rb + guard let regionCode = local.regionCode else { return languageCode } + return "zh" + "-" + regionCode + default: + return languageCode + } + }() let query = Mastodon.API.Account.RegisterQuery( reason: viewModel.reason.value, username: username, email: email, password: password, agreement: true, // user confirmed in the server rules scene - locale: Locale.current.languageCode ?? "en" + locale: locale ) // register without show server rules