开发者社区> 问答> 正文

关于JFinal+freemarker配置I18N的问题?报错

@JFinal 你好,想跟你请教个问题: 想请教下 关于JFinal+freemarker配置I18N的问题,按您说的已经做了相关的配置了还是报异常,读不到配置文件的信息。您能详细的教导下吗? 这个报错是找不到文件还是其它什么问题!

展开
收起
爱吃鱼的程序员 2020-06-22 11:17:45 467 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    ResourceBundle没有找到,可以在config类configConstant方法中配置:

    me.setI18n("message",Locale.SIMPLIFIED_CHINESE,999999999);



    message. properties,message_en_US.properties,message_zh_CN.properties等放在classes目录下即classpath目录,eclipse编辑器直接src目录,maven工程src/main/resources目录回复 @itartisan:我知道问题出在哪了感谢!回复 @itartisan:还是不行,谢谢你回复 @JFinal_Adore:I18N.init("jyConfig",null,null)回复 @itartisan:试了,也不行。我的配置文件是叫jyConfig_zh_CN.properties。是不是要用完整名字喔。回复 @JFinal_Adore:me.setI18n("message",Locale.SIMPLIFIED_CHINESE,999999999);用这种看看。

    ResourceBundle没有找到,可以在config类configConstant方法中配置:

    me.setI18n(" jyConfig",Locale.SIMPLIFIED_CHINESE,999999999);



    创建个拦截器:

    publicclassResourceBundleInterceptorimplementsInterceptor{@Overridepublicvoidintercept(ActionInvocationai){Stringlocal_i18n=ai.getController().getCookie(Const.I18N_LOCALE);ResourceBundleRESOURCE_BUNDLE=null;if(local_i18n==null||local_i18n==""){HttpServletRequestrequest=ai.getController().getRequest();Localelocale=(request!=null)?request.getLocale():Locale.getDefault();if(locale!=null){RESOURCE_BUNDLE=ResourceBundle.getBundle(JFinal.me().getConstants().getI18nResourceBaseName(),locale);}else{RESOURCE_BUNDLE=ResourceBundle.getBundle(JFinal.me().getConstants().getI18nResourceBaseName(),I18N.getDefaultLocale());}}else{RESOURCE_BUNDLE=ResourceBundle.getBundle(JFinal.me().getConstants().getI18nResourceBaseName(),I18N.localeFromString(local_i18n));}ResourceBundleModelrsbm=newResourceBundleModel(RESOURCE_BUNDLE,newBeansWrapper());ai.getController().setAttr("bundle",rsbm);ai.invoke();}}


    先根据cookie判断,没有cookie则根据请求头 Accept-Language。

    看不懂也不会用了,唉...
    2020-06-22 11:18:03
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第15讲】:Spring Boot 2.0 API与Spring REST Docs实战 立即下载
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题) 立即下载