Skip to content

io microsphere i18n AbstractResourceServiceMessageSource

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

AbstractResourceServiceMessageSource

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

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

Overview

Abstract Resource ServiceMessageSource Class that loads messages from resources keyed by Locale.

Example Usage

`// Typically used through DefaultServiceMessageSource
  DefaultServiceMessageSource source = new DefaultServiceMessageSource("test");
  source.init();
  Map> messages = source.getLocalizedResourceMessages();
  // messages keyed by resource name, e.g. "META-INF/i18n/test/i18n_messages_zh_CN.properties"
`

Declaration

public abstract class AbstractResourceServiceMessageSource extends AbstractServiceMessageSource implements

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 through DefaultServiceMessageSource
  DefaultServiceMessageSource source = new DefaultServiceMessageSource("test");
  source.init();
  Map<String, Map<String, String>> messages = source.getLocalizedResourceMessages();
  // messages keyed by resource name, e.g. "META-INF/i18n/test/i18n_messages_zh_CN.properties"

Method Examples

getResource

String resource = source.getResource(Locale.ENGLISH);
  // e.g. "META-INF/i18n/test/i18n_messages_en.properties"

getResources

Map<String, String> messages = source.getMessages(Locale.SIMPLIFIED_CHINESE);
  // e.g. {"test.a": "测试-a", "test.hello": "您好,{}"}
DefaultServiceMessageSource source = new DefaultServiceMessageSource("test");
  source.init();
  Map<String, Map<String, String>> all = source.getLocalizedResourceMessages();
  // 2 entries for zh_CN and en locales

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.AbstractResourceServiceMessageSource;

API Reference

Public Methods

Method Description
getResource The default prefix of of message resource name
getResources Builds the resource name for the given Locale.

Method Details

getResource

public String getResource(Locale locale)

The default prefix of of message resource name / public static final String DEFAULT_RESOURCE_NAME_PREFIX = "i18n_messages_";

/** The default suffix of message resource name / public static final String DEFAULT_RESOURCE_NAME_SUFFIX = ".properties";

private volatile Map> localizedResourceMessages = emptyMap();

/** Constructs with the given source identifier.

getResources

public final Set<String> getResources()

Builds the resource name for the given Locale.


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

Clone this wiki locally