예제 #1
0
 public static string _(string msgId, params object[] @params)
 {
     if (Localizer is null)
     {
         CompositionRoot.WriteMissingInitializationErrorMessage();
         return(@params.Any() ? string.Format(CultureInfo.InvariantCulture, msgId, @params) : msgId);
     }
     return(@params.Any() ? Localizer.Catalog.GetString(msgId, @params) : Localizer.Catalog.GetString(msgId));
 }
예제 #2
0
 public static string GetParticularString(string context, string text, params object[] args)
 {
     if (Localizer is null)
     {
         CompositionRoot.WriteMissingInitializationErrorMessage();
         return(args.Any() ? string.Format(CultureInfo.InvariantCulture, text, args) : text);
     }
     return(args.Any() ? Localizer.Catalog.GetParticularString(context, text, args) : Localizer.Catalog.GetParticularString(context, text));
 }
예제 #3
0
        private string Gettext()
        {
            if (Localizer is null)
            {
                CompositionRoot.WriteMissingInitializationErrorMessage();
                return(MsgId);
            }

            return(Params.Any() ? Localizer.Catalog.GetString(MsgId, Params) : Localizer.Catalog.GetString(MsgId));
        }
예제 #4
0
        [StringFormatMethod("pluralMsgId")] //< not yet supported, #1833369.
        public static string PluralGettext(int n, string singularMsgId, string pluralMsgId, params object[] @params)
        {
            if (Localizer is null)
            {
                CompositionRoot.WriteMissingInitializationErrorMessage();
                return(string.Format(CultureInfo.InvariantCulture, n == 1 ? singularMsgId : pluralMsgId, @params));
            }

            return(@params.Any()
                ? Localizer.Catalog.GetPluralString(singularMsgId, pluralMsgId, n, @params)
                : Localizer.Catalog.GetPluralString(singularMsgId, pluralMsgId, n));
        }
        public void Execute(object parameter)
        {
            if (CultureTracker is null)
            {
                CompositionRoot.WriteMissingInitializationErrorMessage();
                return;
            }

            CultureTracker.CurrentCulture =
                CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                .Single(cultureInfo => cultureInfo.Name == (string)parameter);
        }
예제 #6
0
        protected override void OnAttached()
        {
            if (!DesignerProperties.GetIsInDesignMode(AssociatedObject))
            {
                if (CultureTracker is null)
                {
                    CompositionRoot.WriteMissingInitializationErrorMessage();
                    return;
                }
                CultureTracker.AddWeakCultureObserver(this);
                UpdateAssociatedObjectCulture();
            }

            base.OnAttached();
        }
예제 #7
0
        internal static string Gettext(this ILocalizer @this, string msgId)
        {
            if (msgId is null)
            {
                return(null);
            }

            var msgIdWithContext = ConvertToMsgIdWithContext(msgId);

            if (@this is null)
            {
                CompositionRoot.WriteMissingInitializationErrorMessage();
                return(msgIdWithContext.MsgId);
            }

            var text   = msgIdWithContext.MsgId;
            var result = string.Empty;

            foreach (var catalog in @this.Catalogs)
            {
                if (msgIdWithContext.Context != null)
                {
                    result = catalog.GetParticularString(msgIdWithContext.Context, msgIdWithContext.MsgId);

                    if (result.Equals(text))
                    {
                        continue;
                    }

                    break;
                }

                result = catalog.GetString(msgIdWithContext.MsgId);

                if (result.Equals(text))
                {
                    continue;
                }

                break;
            }

            text = result;

            return(text);
        }
예제 #8
0
        internal static string Gettext(this ILocalizer @this, string msgId, params object[] values)
        {
            if (msgId is null)
            {
                return(null);
            }

            var msgIdWithContext = ConvertToMsgIdWithContext(msgId);

            if (@this is null)
            {
                CompositionRoot.WriteMissingInitializationErrorMessage();
                return(string.Format(msgIdWithContext.MsgId, values));
            }

            if (msgIdWithContext.Context != null)
            {
                return(@this.Catalog.GetParticularString(msgIdWithContext.Context, msgIdWithContext.MsgId, values));
            }
            return(@this.Catalog.GetString(msgIdWithContext.MsgId, values));
        }