Exemplo n.º 1
0
            public bool TryUpdate(CultureInfo cultureInfo)
            {
                if (!Culture.NameEquals(cultureInfo, this.culture))
                {
                    lock (this.gate)
                    {
                        if (!Culture.NameEquals(cultureInfo, this.culture))
                        {
                            this.culture = cultureInfo;
                            var newValue = Translator.Translate(
                                this.translation.resourceManager,
                                this.translation.Key,
                                cultureInfo,
                                this.translation.ErrorHandling);
                            var changed = newValue != this.value;
                            this.value = newValue;
                            return(changed);
                        }

                        return(false);
                    }
                }

                return(false);
            }
Exemplo n.º 2
0
                public bool TryGetValue(CultureInfo key, [MaybeNullWhen(false)] out string?value)
                {
                    foreach (var keyValuePair in this.translations)
                    {
                        if (Culture.NameEquals(keyValuePair.Key, key))
                        {
                            value = keyValuePair.Value;
                            return(true);
                        }
                    }

                    value = null;
                    return(false);
                }
Exemplo n.º 3
0
            internal bool TryUpdate(CultureInfo cultureInfo)
            {
                if (ShouldUpdate())
                {
                    lock (this.gate)
                    {
                        if (ShouldUpdate())
                        {
                            this.culture = cultureInfo;
                            var newValue = Translator.Translate(
                                this.translation.resourceManager,
                                this.translation.Key,
                                cultureInfo,
                                this.translation.ErrorHandling);
                            var changed = newValue != this.value;
                            this.value = newValue;
                            return(changed);
                        }

                        return(false);
                    }
                }

                return(false);

                bool ShouldUpdate()
                {
                    if (cultureInfo is null && this.culture is null)
                    {
                        return(false);
                    }

                    if (cultureInfo is null || this.culture is null)
                    {
                        return(true);
                    }

                    return(!Culture.NameEquals(cultureInfo, this.culture));
                }
            }
Exemplo n.º 4
0
 public bool ContainsKey(CultureInfo key) => this.translations.Any(x => Culture.NameEquals(x.Key, key));