Skip to content

io microsphere i18n AbstractServiceMessageSource

github-actions[bot] edited this page Jul 9, 2026 · 12 revisions

AbstractServiceMessageSource

Type: Class | Module: microsphere-i18n-core | Package: io.microsphere.i18n | Since: 1.0.0

Source: microsphere-i18n-core/src/main/java/io/microsphere/i18n/AbstractServiceMessageSource.java

Overview

Abstract ServiceMessageSource providing base implementation for message resolution, locale management, and message code resolution.

Example Usage

`// Typically used via concrete subclass such as DefaultServiceMessageSource
  DefaultServiceMessageSource source = new DefaultServiceMessageSource("test");
  source.setSupportedLocales(Arrays.asList(Locale.SIMPLIFIED_CHINESE, Locale.ENGLISH));
  source.init();
  String msg = source.getMessage("hello", Locale.ENGLISH, "World"); // "Hello,World"
`

Declaration

public abstract class AbstractServiceMessageSource implements ServiceMessageSource

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.17-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Typically used via concrete subclass such as DefaultServiceMessageSource
  DefaultServiceMessageSource source = new DefaultServiceMessageSource("test");
  source.setSupportedLocales(Arrays.asList(Locale.SIMPLIFIED_CHINESE, Locale.ENGLISH));
  source.init();
  String msg = source.getMessage("hello", Locale.ENGLISH, "World"); // "Hello,World"

Method Examples

setDefaultLocale

DefaultServiceMessageSource source = new DefaultServiceMessageSource("test");
source.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);

setSupportedLocales

source.setSupportedLocales(Arrays.asList(Locale.SIMPLIFIED_CHINESE, Locale.ENGLISH));

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-i18n-core</artifactId>
    <version>${microsphere-i18n.version}</version>
</dependency>

Tip: Use the BOM (microsphere-i18n-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.i18n.AbstractServiceMessageSource;

API Reference

Public Methods

Method Description
setDefaultLocale Constructs an AbstractServiceMessageSource with the given source name.
setSupportedLocales Sets the supported Locale locales for this message source.

Method Details

setDefaultLocale

public final void setDefaultLocale(Locale defaultLocale)

Constructs an AbstractServiceMessageSource with the given source name.

Example Usage

`DefaultServiceMessageSource source = new DefaultServiceMessageSource("test");
`

setSupportedLocales

public final void setSupportedLocales(Collection<Locale> supportedLocales)

Sets the supported Locale locales for this message source.

Example Usage

`source.setSupportedLocales(Arrays.asList(Locale.SIMPLIFIED_CHINESE, Locale.ENGLISH));
`

This documentation was auto-generated from the source code of microsphere-i18n.

Clone this wiki locally