كيفية تدويل محتويات أخرى لموقعنا (مثل القوائم والعناوين وما إلى ذلك)؟ هذا ما يريد هذا المقال أن يصنعه -> التدويل.
المحتوى المضافة في ملف spring.xml للمشروع هو كما يلي
<mvc: interceptors> <span style = "White-Space: pre"> </span> <!-إذا كان اعتراض التشغيل الدولي يعتمد على (طلب/جلسة/ملف تعريف ارتباط) ، فيجب تكوينه-> <bean/> </mvc: Interceptors>
أضف ثلاثة ملفات في موارد المجلد المصدر في المشروع: myProperties.Properties و MyProperties_zh_properties و MyProperties_en_properties
فيما يلي بعض المعلومات البسيطة حول صفحة JSP ، فقط العرض التوضيحي وليس الاعتبارات الأخرى:
<٪@ page language = "java" contentType = "text/html ؛ charset = utf-8" pageencoding = "utf-8" ٪> <! <html> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = utf-8"> <title> إدراج العنوان هنا </title> </head> <٪ name = (locale) session.getAttribute ("i18nlanguage") ؛ ResourceBundle MyResourceSbundle = ResourceBundle.getBundle ("MyProperties" ، الاسم) ؛ ٪> <Body> <a href = "$ {pagecontext.request.contextpath} /index/findex.do؟langtype=en&page=home"> eng </a> | <a href = "$ {pagecontext.request.contextpath} /index/findex.do؟langtype=zh&page=home"> <٪ = myResourceBundle.getString ("Simplified") </a> </html>رمز طبقة عمل الخلفية كما يلي:
حزمة com.zhidao.oms.index ؛ استيراد java.util.locale ؛ استيراد javax.servlet.http.httpservletrequest ؛ استيراد org.springframework.stereotype.controller ؛ استيراد org.springframework.web.bind.annotation.requestmapping ؛ استيراد org.springframework.web.bind.annotation.requestparam ؛ controller @requestmapping ("/index") الفئة العامة indexAction { @requestmapping ("/findex") السلسلة العامة findex (httpservletrequest request ، @requestparam string langtype ، string page) {if (langtype.equals ("zh") {locale locale = new locale = request.getSession (). setAttribute ("i18nlanguage" ، locale) ؛ } else if (langtype.equals ("en")) {locale locale = new locale ("en" ، "us") ؛ request.getSession (). setAttribute ("i18nlanguage" ، locale) ؛ } آخر {request.getSession (). setAttribute ("i18nlanguage" ، locale.getDefault ()) ؛ } إرجاع "/front/"+ page+".jsp" ؛ }}مجرد اختبار الاداءات ذات الصلة! آمل أن ينتقد الجميع وتصحيح الأشياء السيئة التي كتبتها.
طريقة التدويل أعلاه القائمة على الجلسة هي كل المحتوى الذي شاركه المحرر. آمل أن يعطيك مرجعًا وآمل أن تتمكن من دعم wulin.com أكثر.