• R/O
  • HTTP
  • SSH
  • HTTPS

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

File Info

Rev. c3a256ccb4a9a5823695d2237d31680b12931560
Size 3,543 bytes
Time 2022-11-29 23:54:33
Author yoshy
Log Message

[MOD] キャプション書式化機能でキャプションの取得と書式化を行う機能の区別を明確にした

Content

namespace CleanAuLait.Core.Resource
{
    public class CaptionFormatter : ICaptionFormatter
    {
        public const string MSG_KEY_CAPTION = "Caption";

        public const string MSG_KEY_PREFIX_CAPTION_FORMAT = "Caption.Format.";

        public const string MSG_KEY_CAPTION_FORMAT_INFO = MSG_KEY_PREFIX_CAPTION_FORMAT + "Info";
        public const string MSG_KEY_CAPTION_FORMAT_WARN = MSG_KEY_PREFIX_CAPTION_FORMAT + "Warn";
        public const string MSG_KEY_CAPTION_FORMAT_ERROR = MSG_KEY_PREFIX_CAPTION_FORMAT + "Error";
        public const string MSG_KEY_CAPTION_FORMAT_CONFIRM = MSG_KEY_PREFIX_CAPTION_FORMAT + "Confirm";
        public const string MSG_KEY_CAPTION_FORMAT_EXCEPTION = MSG_KEY_PREFIX_CAPTION_FORMAT + "Exception";
        
        protected readonly IMessageRepository repo;

        public CaptionFormatter(IMessageRepository repo)
        {
            this.repo = repo;
        }

        public string GetDefaultCaption()
        {
            return GetCaption(MSG_KEY_CAPTION);
        }

        public string GetCaption(string captionKey)
        {
            return this.repo.Get(captionKey);
        }

        public string GetInfoCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_INFO);
        }

        public string FormatInfoCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_INFO, captionKey);
        }

        public string GetWarnCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_WARN);
        }

        public string FormatWarnCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_WARN, captionKey);
        }

        public string GetErrorCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_ERROR);
        }

        public string FormatErrorCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_ERROR, captionKey);
        }

        public string GetConfirmCaption()
        {
            return FormatDefaultCaption(MSG_KEY_CAPTION_FORMAT_ERROR);
        }

        public string FormatConfirmCaption(string captionKey)
        {
            return FormatCaption(MSG_KEY_CAPTION_FORMAT_CONFIRM, captionKey);
        }

        public string GetExceptionCaption(Exception e)
        {
            return FormatExceptionCaption(e, null);
        }

        public string FormatExceptionCaption(Exception e, string captionKey)
        {
            string caption;

            if (string.IsNullOrEmpty(captionKey))
            {
                caption = GetDefaultCaption();
            }
            else
            {
                caption = GetCaption(captionKey);
            }

            string format = GetCaption(MSG_KEY_CAPTION_FORMAT_EXCEPTION);

            return string.Format(format, caption, e.GetType().Name);
        }

        protected string FormatDefaultCaption(string captionFormatKey)
        {
            return FormatCaption(captionFormatKey, null);
        }

        protected string FormatCaption(string captionFormatKey, string captionKey)
        {
            string caption;

            if (string.IsNullOrEmpty(captionKey))
            {
                caption = GetDefaultCaption();
            }
            else
            {
                caption = GetCaption(captionKey);
            }

            string format = GetCaption(captionFormatKey);

            return string.Format(format, caption);
        }

    }
}