Skip to content

Instantly share code, notes, and snippets.

@normal-carrot
Created December 5, 2017 11:10
Show Gist options
  • Select an option

  • Save normal-carrot/c1cbca50202bfa3f16faa0c3e1ceadce to your computer and use it in GitHub Desktop.

Select an option

Save normal-carrot/c1cbca50202bfa3f16faa0c3e1ceadce to your computer and use it in GitHub Desktop.

Revisions

  1. Alexander Kohonovsky created this gist Dec 5, 2017.
    24 changes: 24 additions & 0 deletions Messages.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import org.springframework.context.MessageSource;
    import org.springframework.context.support.MessageSourceAccessor;
    import org.springframework.stereotype.Component;

    import java.util.Locale;

    /**
    * @author saniaky
    * @since 12/5/17
    */
    @Component
    public class Messages {

    private final MessageSourceAccessor accessor;

    public Messages(MessageSource messageSource) {
    this.accessor = new MessageSourceAccessor(messageSource, LocaleContextHolder.getLocale());
    }

    public String get(String code) {
    return accessor.getMessage(code);
    }

    }