1 // Copyright (c) 2024 Samsung Electronics Co., Ltd.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
16 extern alias TizenSystemSettings;
17 using TizenSystemSettings.Tizen.System;
19 using System.Runtime.InteropServices;
20 using System.Collections.Generic;
22 using System.ComponentModel;
24 namespace Tizen.NUI.Visuals
27 /// The text visual with advanced options.
30 /// It will be used when we want to control TextVisual with more options.
31 /// This visual allow to translated text with SID.
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public class AdvancedTextVisual : Visuals.TextVisual
37 private string textLabelSid = null;
39 private static Tizen.NUI.SystemLocaleLanguageChanged systemLocaleLanguageChanged = new Tizen.NUI.SystemLocaleLanguageChanged();
40 private bool hasSystemLanguageChanged = false;
44 public AdvancedTextVisual() : base()
49 #region Visual Properties
51 /// The TranslatableText property.<br />
52 /// The text can set the SID value.<br />
54 /// <exception cref='global::System.ArgumentNullException'>
55 /// ResourceManager about multilingual is null.
57 public string TranslatableText
65 if (NUIApplication.MultilingualResourceManager == null)
67 throw new global::System.ArgumentNullException(null, "ResourceManager about multilingual is null");
69 string translatableText = null;
71 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new global::System.Globalization.CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
73 if (translatableText != null)
75 Text = translatableText;
76 if (hasSystemLanguageChanged == false)
78 systemLocaleLanguageChanged.Add(SystemSettingsLocaleLanguageChanged);
79 hasSystemLanguageChanged = true;
90 #region Internal Method
91 private void SystemSettingsLocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
93 string translatableText = null;
94 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new global::System.Globalization.CultureInfo(e.Value.Replace("_", "-")));
95 if (translatableText != null)
97 Text = translatableText;
101 Tizen.Log.Error("NUI", $"Fail to get translated text : {textLabelSid};");
107 [EditorBrowsable(EditorBrowsableState.Never)]
108 protected override void Dispose(DisposeTypes type)
115 if (hasSystemLanguageChanged)
117 systemLocaleLanguageChanged.Remove(SystemSettingsLocaleLanguageChanged);