- Add class-level documentation for all mapper and multilingual classes - Add complete javadoc for all public methods with @param and @return tags - Add field-level comments for better code readability - Improve documentation for initialization blocks and constructors Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
48 lines
1.1 KiB
Java
48 lines
1.1 KiB
Java
package com.imyeyu.lang.mapper;
|
||
|
||
import com.imyeyu.io.IO;
|
||
import com.imyeyu.java.bean.Language;
|
||
|
||
import java.io.FileNotFoundException;
|
||
import java.io.InputStream;
|
||
import java.io.InputStreamReader;
|
||
import java.util.Properties;
|
||
|
||
/**
|
||
* 资源文件语言映射
|
||
*
|
||
* @author 夜雨
|
||
* @version 2024-04-09 00:55
|
||
*/
|
||
public class ResourcesLanguageMap extends PropertiesLanguageMap {
|
||
|
||
/**
|
||
* 默认构造
|
||
*
|
||
* @param language 所属语言
|
||
*/
|
||
public ResourcesLanguageMap(Language.Enum language) {
|
||
super(language);
|
||
}
|
||
|
||
/**
|
||
* 加载资源文件,格式化 % 为 {@link Language.Enum#toString()},示例:lang/app_%s.lang
|
||
*
|
||
* @param path 路径
|
||
*/
|
||
public void load(String path) {
|
||
try {
|
||
InputStream is = IO.resourceToInputStream(getClass(), path.formatted(language.toString()));
|
||
if (is != null) {
|
||
Properties properties = new Properties();
|
||
properties.load(new InputStreamReader(is));
|
||
load(properties);
|
||
} else {
|
||
throw new FileNotFoundException("not found language properties file: " + path.formatted(language.toString()));
|
||
}
|
||
} catch (Exception e) {
|
||
throw new RuntimeException("load language properties file error", e);
|
||
}
|
||
}
|
||
}
|