<commit_before>﻿using System.Collections.Generic;
#if UNITY_5 || UNITY_2017_1_OR_NEWER
using JetBrains.Annotations;
#endif
using UnityEngine;

namespace Polyglot
{
    public abstract class LocalizedTextComponent<T> : MonoBehaviour, ILocalize where T : Component
    {
        [Tooltip("The text component to localize")]
        [SerializeField]
        private T text;

        [Tooltip("The key to localize with")]
        [SerializeField]
        private string key;
        public string Key
        {
            get
            {
                return key;
            }
            set
            {
                key = value;
                OnLocalize();
            }
        }

        public List<object> Parameters { get { return parameters; } }

        private List<object> parameters = new List<object>();

#if UNITY_5 || UNITY_2017_1_OR_NEWER
        [UsedImplicitly]
#endif
        public void Reset()
        {
            text = GetComponent<T>();
        }

#if UNITY_5 || UNITY_2017_1_OR_NEWER
        [UsedImplicitly]
#endif

        public void OnEnable()
        {
            Localization.Instance.AddOnLocalizeEvent(this);
        }

        protected abstract void SetText(T component, string value);

        protected abstract void UpdateAlignment(T component, LanguageDirection direction);

        public void OnLocalize()
        {
#if UNITY_EDITOR
            var flags = text != null ? text.hideFlags : HideFlags.None;
            if(text != null) text.hideFlags = HideFlags.DontSave;
#endif
            if (parameters != null && parameters.Count > 0)
            {
                SetText(text, Localization.GetFormat(key, parameters.ToArray()));
            }
            else
            {
                SetText(text, Localization.Get(key));
            }

            var direction = Localization.Instance.SelectedLanguageDirection;

            if (text != null) UpdateAlignment(text, direction);

#if UNITY_EDITOR
            if (text != null) text.hideFlags = flags;
#endif
        }
        
        public void ClearParameters()
        {
            parameters.Clear();
        }

        public void AddParameter(object parameter)
        {
            parameters.Add(parameter);
            OnLocalize();
        }
        public void AddParameter(int parameter)
        {
            AddParameter((object)parameter);
        }
        public void AddParameter(float parameter)
        {
            AddParameter((object)parameter);
        }
        public void AddParameter(string parameter)
        {
            AddParameter((object)parameter);
        }
    }
}<commit_msg>Added a toggle to LocalizedTextComponent that can control if you want polyglot to use ltr or rtl language settings<commit_after>﻿using System.Collections.Generic;
#if UNITY_5 || UNITY_2017_1_OR_NEWER
using JetBrains.Annotations;
#endif
using UnityEngine;

namespace Polyglot
{
    public abstract class LocalizedTextComponent<T> : MonoBehaviour, ILocalize where T : Component
    {
        [Tooltip("The text component to localize")]
        [SerializeField]
        private T text;

        [Tooltip("The key to localize with")]
        [SerializeField]
        private string key;

        public string Key
        {
            get { return key; }
            set
            {
                key = value;
                OnLocalize();
            }
        }

        public List<object> Parameters { get { return parameters; } }

        private List<object> parameters = new List<object>();

        [SerializeField]
        private bool useLanguageAlignment = true;

#if UNITY_5 || UNITY_2017_1_OR_NEWER
        [UsedImplicitly]
#endif
        public void Reset()
        {
            text = GetComponent<T>();
        }

#if UNITY_5 || UNITY_2017_1_OR_NEWER
        [UsedImplicitly]
#endif
        public void OnEnable()
        {
            Localization.Instance.AddOnLocalizeEvent(this);
        }

        protected abstract void SetText(T component, string value);

        protected abstract void UpdateAlignment(T component, LanguageDirection direction);

        public void OnLocalize()
        {
#if UNITY_EDITOR
            var flags = text != null ? text.hideFlags : HideFlags.None;
            if(text != null) text.hideFlags = HideFlags.DontSave;
#endif
            if (parameters != null && parameters.Count > 0)
            {
                SetText(text, Localization.GetFormat(key, parameters.ToArray()));
            }
            else
            {
                SetText(text, Localization.Get(key));
            }

            var direction = Localization.Instance.SelectedLanguageDirection;

            if (useLanguageAlignment && text != null) UpdateAlignment(text, direction);

#if UNITY_EDITOR
            if (text != null) text.hideFlags = flags;
#endif
        }

        public void ClearParameters()
        {
            parameters.Clear();
        }

        public void AddParameter(object parameter)
        {
            parameters.Add(parameter);
            OnLocalize();
        }
        public void AddParameter(int parameter)
        {
            AddParameter((object)parameter);
        }
        public void AddParameter(float parameter)
        {
            AddParameter((object)parameter);
        }
        public void AddParameter(string parameter)
        {
            AddParameter((object)parameter);
        }
    }
}
{'fraction_non_alphanumeric': 0.08461112137446887, 'fraction_numerical': 0.007020136707925365, 'mean_word_length': 1.825678496868476, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5893631', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1375, 'n_words': 346}