多语言(英语、法语、西班牙语、德语、波兰语、阿拉伯语)处理

This commit is contained in:
2026-01-12 09:37:20 +08:00
parent 219caadd45
commit 41f0b72253
113 changed files with 3593 additions and 464 deletions

View File

@ -5,7 +5,7 @@ import java.lang.annotation.*;
/**
*
* 切换为英文环境后,不支持配置操作
* 切换为其它语言环境后,不支持配置操作
* @author kerwin
*/
@Target(ElementType.METHOD)

View File

@ -734,14 +734,30 @@ public interface CommonConstant {
String MSG = "设备接入通道";
String MSG_EN = "Equipment access channel ";
String MSG_FRA = "Canal d'accès à l'équipement ";
String MSG_SPA = "Canal de acceso al dispositivo ";
String MSG_DE = "Gerätezugriffskanal ";
String MSG_PL = "Dostęp do urządzeń ";
String MSG_ARA = "جهاز الوصول إلى القناة ";
String SUCCESS = "恢复";
String SUCCESS_EN = "recover";
String SUCCESS_EN = "Recover";
String SUCCESS_FRA = "Récupération";
String SUCCESS_SPA = "Recuperar";
String SUCCESS_DE = "Wiederherstellung";
String SUCCESS_PL = "Przywrócić";
String SUCCESS_ARA = "استعاد";
String FAIL = "断开";
String FAIL_EN = " disconnect";
String FAIL_EN = "Disconnect";
String FAIL_FRA = "Déconnecter";
String FAIL_SPA = " Desconexión";
String FAIL_DE = " Trennen";
String FAIL_PL = " Odłącz";
String FAIL_ARA = " قطع الاتصال";
String SN_FAIL = "设备接入点离线";
@ -768,6 +784,11 @@ public interface CommonConstant {
String DEVICE_NO_SN = "设备没有配置SN";
String DEVICE_NO_SN_EN = "The device is not configured with SN";
String DEVICE_NO_SN_FRA = "L'appareil n'est pas configuré SN";
String DEVICE_NO_SN_SPA = "El dispositivo no está configurado con SN";
String DEVICE_NO_SN_DE = "Gerät ohne SN konfiguriert";
String DEVICE_NO_SN_PL = "Urządzenie nie ma skonfigurowanego SN";
String DEVICE_NO_SN_ARA = "الجهاز لم يتم تكوين SN";
String NOT_SN = "没有配置站内接入点";
String INTERVAL = "间隔";
String STATION = "电站";
@ -1003,8 +1024,56 @@ public interface CommonConstant {
String JOIN_STATION_ID = "\\_";
String REPORT_NAME="月度报表";
String REPORT_NAME_EN="monthly report";
String REPORT_NAME_EN="Monthly report";
String REPORT_NAME_FRA="Déclaration mensuelle";
String REPORT_NAME_SPA="Estado mensual";
String REPORT_NAME_DE="Monatlicher Bericht";
String REPORT_NAME_PL="Raport miesięczny";
String REPORT_NAME_ARA="تقرير شهري";
String BILL_NAME="月度账单";
String BILL_NAME_EN="monthly bill";
String BILL_NAME_EN="Monthly bill";
String BILL_NAME_FRA="Facturation mensuelle";
String BILL_NAME_SPA="Factura mensual";
String BILL_NAME_DE="Monatliche Rechnung";
String BILL_NAME_PL="Rachunki miesięczne";
String BILL_NAME_ARA="فاتورة شهرية";
// 语言切换
String LANG = "lang";
// 调用api 需要用到的参数
interface lang{
// 中文
String ZH = "zh";
// 英语
String EN = "en";
// 法语
String FRA = "fra";
// 西班牙
String SPA = "spa";
// 德语
String DE = "de";
// 波兰
String PL = "pl";
// 阿拉伯语
String ARA = "ara";
}
// web / app 端切换语言用到的参数
interface langTemp{
// 简体中文
String ZH_CN="zh_CN";
// 美式英语
String EN_US="en_US";
// 法语
String FR_FR="fr_FR";
// 西班牙语
String ES_ES="es_ES";
// 德语
String DE_DE="de_DE";
// 波兰语
String PL_PL="pl_PL";
// 阿拉伯语
String AR_EG="ar_EG";
}
}

View File

@ -27,10 +27,20 @@ public interface DefineConstant {
String SUMMARY = "汇总";
String SUMMARY_EN = "Summary";
String SUMMARY_FRA = "résumé";
String SUMMARY_SPA = "Resumen";
String SUMMARY_DE = "Zusammenfassung";
String SUMMARY_PL = "Podsumowanie";
String SUMMARY_ARA = "ملخص";
String SUMMARY_DATA_STATION = "电站汇总数据";
String SUMMARY_DATA_STATION_EN = "Summary data of power station";
String SUMMARY_DATA_STATION_FRA = "Données sommaires de la station";
String SUMMARY_DATA_STATION_SPA = "Datos agregados de la central eléctrica";
String SUMMARY_DATA_STATION_DE = "Kraftwerksdaten zusammengefasst";
String SUMMARY_DATA_STATION_PL = "Podsumowanie danych elektrowni";
String SUMMARY_DATA_STATION_ARA = "محطة توليد الكهرباء بيانات موجزة";
interface PeakShaving {
String ADD_TEMPLATE_SUCCESS = "新增计划曲线模板成功";
@ -82,11 +92,21 @@ public interface DefineConstant {
String ANTI_BACKFLOW_METER = "防逆流表";
String TOTAL_ACTIVE_POWER = "总有功功率";
String BUILDING = "(在建)";
String BUILDING_EN = "(Under construction)";
String BUILDING_FRA = "(En construction)";
String BUILDING_SPA = "(En construcción)";
String BUILDING_DE = "(Im Bau)";
String BUILDING_PL = "(W budowie)";
String BUILDING_ARA = "(تحت الإنشاء)";
String BUILDING_EN = "(under construction)";
String PROPOSED = "(拟建)";
String PROPOSED_EN = "(proposed)";
String PROPOSED_EN = "(Proposed)";
String PROPOSED_FRA = "(Proposé)";
String PROPOSED_SPA = "(Propuesta)";
String PROPOSED_DE = "(Erstellbar)";
String PROPOSED_PL = "(Proponowane)";
String PROPOSED_ARA = "(مقترح)";
}
interface PlanningPolicy{
@ -108,7 +128,13 @@ public interface DefineConstant {
interface PointDemo{
String TIME = "时间";
String TIME_EN = "time";
String TIME_EN = "Time";
String TIME_FRA = "Données";
String TIME_SPA = "Datos";
String TIME_DE = "Daten";
String TIME_PL = "Dane";
String TIME_ARA = "داتا";
}
interface DeviceTypeCol{

View File

@ -221,10 +221,7 @@ public interface RedisKeyConstant {
String LOGIN_TYPE_ACCOUNT = "account";
//登陆方式 phone 手机号
String LOGIN_TYPE_PHONE = "phone";
// 语言切换
String LANG="lang";
String EN_US="en_US";
}
//设备相关

View File

@ -47,4 +47,7 @@ public class SimpleUser implements Serializable {
//工作流租户id
String tenantId;
@ApiModelProperty(value = "多语言切换-查询字段")
private String lang;
}

View File

@ -9,6 +9,10 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author kerwin
@ -19,13 +23,17 @@ import java.net.*;
@Slf4j
public class AbroadAddressUtils {
static String apiKey = "AIzaSyAM4JOtE9yt48f60ATwByB7uWzTIrYSSUg";
static String APIKEY = "AIzaSyAM4JOtE9yt48f60ATwByB7uWzTIrYSSUg";
// 正则表达式-中文字符
static String PATTERN1 = "[\u4e00-\u9fff]";
// 正则表达式-数字
static String PATTERN2 = "\\d";
public static MyAddress getAddress(String lat, String lng){
// 构建API请求URL
String urlString = "https://maps.googleapis.com/maps/api/geocode/json?" +
"latlng=" + lat + "," + lng +
"&key=" + apiKey;
"&language=zh-CN&key=" + APIKEY;
// 发送HTTP请求
URL url = null;
StringBuilder response = new StringBuilder();
@ -57,8 +65,6 @@ public class AbroadAddressUtils {
} catch (IOException e) {
throw new RuntimeException(e);
}
// 解析JSON响应
return parseGeocodeResponse(response.toString());
}
@ -72,33 +78,41 @@ public class AbroadAddressUtils {
}
MyAddress address = new MyAddress();
// 获取第一个结果(最精确的匹配)
JSONObject firstResult = json.getJSONArray("results").getJSONObject(0);
// 解析地址组件
JSONArray components = firstResult.getJSONArray("address_components");
for (int i = 0; i < components.length(); i++) {
JSONObject component = components.getJSONObject(i);
JSONArray types = component.getJSONArray("types");
String longName = component.getString("long_name");
// 国家信息
if (types.toString().contains("country")) {
address.setNation(longName);
}
// 省份/州信息
if (types.toString().contains("administrative_area_level_1")) {
address.setProvince(longName);
}
// 城市信息
if (types.toString().contains("locality")) {
address.setCity(longName);
}
// 区县信息
if (types.toString().contains("sublocality")) {
address.setDistrict(longName);
}
// 邮政编码
if (types.toString().contains("postal_code")) {
address.setCityCode(longName);
JSONArray results = json.getJSONArray("results");
for (int j = 0; j < results.length(); j++){
JSONObject result = json.getJSONArray("results").getJSONObject(j);
// 解析地址组件
JSONArray components = result.getJSONArray("address_components");
for (int i = 0; i < components.length(); i++) {
JSONObject component = components.getJSONObject(i);
JSONArray types = component.getJSONArray("types");
String longName = component.getString("long_name");
Pattern p1 = Pattern.compile(PATTERN1);
Pattern p2 = Pattern.compile(PATTERN2);
Matcher m1 = p1.matcher(longName);
Matcher m2 = p2.matcher(longName);
if(m1.find() || m2.find()){
// 国家信息
if (types.toString().contains("country")) {
address.setNation(longName);
}
// 省份/州信息
if (types.toString().contains("administrative_area_level_1")) {
address.setProvince(longName);
}
// 城市信息
if (types.toString().contains("locality")) {
address.setCity(longName);
}
// 区县信息
if (types.toString().contains("sublocality")) {
address.setDistrict(longName);
}
// 邮政编码
if (types.toString().contains("postal_code")) {
address.setCityCode(longName);
}
}
}
}
return address;
@ -106,8 +120,8 @@ public class AbroadAddressUtils {
public static void main(String[] args) {
// 示例坐标 - 纽约
String latitude = "48.877132";
String longitude = "2.356407";
String latitude = "49.102024";
String longitude = "31.136961";
try {
// 获取地址信息

View File

@ -21,10 +21,10 @@ public class TranslateUtils {
// 静态翻译方法:输入待翻译文本,返回目标语言文本
public static String translate(String text) {
public static String translate(String text,String lang) {
MediaType mediaType = MediaType.parse("application/json");
// 动态构建请求体(支持任意文本)
String jsonBody = String.format("{\"from\":\"zh\",\"to\":\"en\",\"q\":\"%s\"}", text);
String jsonBody = String.format("{\"from\":\"zh\",\"to\":\""+lang+"\",\"q\":\"%s\"}", text);
RequestBody body = RequestBody.create(mediaType, jsonBody);
Request request = null;
@ -63,7 +63,7 @@ public class TranslateUtils {
// 示例调用
public static void main(String[] args) throws IOException {
String translated = translate("PCS环境过温降额[恢复]");
String translated = translate("电站汇总数据","fra");
System.out.println("翻译结果: " + translated); // 输出: active power
}