Browse Source

!6 !5 update I18nLocaleResolver.java.

Merge pull request !6 from blue/master
master
blue 1 year ago
committed by Gitee
parent
commit
3d757cc5e9
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
  1. 21
      LICENSE
  2. 3
      im-admin-ui/src/components/ImageUpload/index.vue
  3. 33
      im-admin/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/core/I18nLocaleResolver.java

21
LICENSE

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 blue
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
im-admin-ui/src/components/ImageUpload/index.vue

@ -59,7 +59,7 @@ const props = defineProps({
}); });
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue', 'on-success']);
const dialogImageUrl = ref(''); const dialogImageUrl = ref('');
const dialogVisible = ref(false); const dialogVisible = ref(false);
@ -99,6 +99,7 @@ const handleBeforeUpload = (file: any) => {
// //
const handleUploadSuccess = (res: any) => { const handleUploadSuccess = (res: any) => {
if (res.code === 200) { if (res.code === 200) {
emit('on-success', res.data);
emit('update:modelValue', res.data.originUrl); emit('update:modelValue', res.data.originUrl);
} else { } else {
emit('update:modelValue', ''); emit('update:modelValue', '');

33
im-admin/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/core/I18nLocaleResolver.java

@ -15,12 +15,35 @@ public class I18nLocaleResolver implements LocaleResolver {
@Override @Override
public Locale resolveLocale(HttpServletRequest httpServletRequest) { public Locale resolveLocale(HttpServletRequest httpServletRequest) {
String language = httpServletRequest.getHeader("content-language"); String languageHeader = httpServletRequest.getHeader("content-language");
Locale locale = Locale.getDefault(); Locale locale;
if (language != null && language.length() > 0) {
String[] split = language.split("_"); if (languageHeader != null && !languageHeader.isEmpty()) {
locale = new Locale(split[0], split[1]); // 处理可能的逗号分隔的语言列表
String[] languages = languageHeader.split(",");
String preferredLanguage = languages[0]; // 取第一个语言标签作为首选
// 处理语言标签的格式(可能包含语言、国家、区域)
String[] parts = preferredLanguage.split("-");
switch (parts.length) {
case 1: // 只有语言代码
locale = new Locale(parts[0]);
break;
case 2: // 语言代码和国家代码
locale = new Locale(parts[0], parts[1]);
break;
case 3: // 语言代码、国家代码和区域代码
locale = new Locale(parts[0], parts[1], parts[2]);
break;
default: // 默认回退到默认语言环境
locale = Locale.getDefault();
break;
} }
} else {
// 如果没有 content-language 头部,使用默认语言环境
locale = Locale.getDefault();
}
return locale; return locale;
} }

Loading…
Cancel
Save