データベースを裏付けi18nのためのjava webアプリ
-
09-06-2019 - |
質問
利用したいデータベースを格納i18nキーと値のペアを改変/リロードのi18nデータで行います。で行う。又は誰でもいい、という考え方を実施。っくりとした複数のスレッドがすがしたいと思っている実践的な解決策です。
私は具体的には参照うに思いをjstlタグなど
<fmt:setlocale>
<fmt:bundle>
<fmt:setBundle>
<fmt:message>
と思うこれは伸びるResourceBundleですが、やってみるとかの問題がなければいけなかったのにjstlタグのリソースを取得すまいりました。
解決
ていただける方法を求める店UTF-8/16文字DB?mysqlでなく構築するとUTF8支援を設定するデフォルトとして、指定したり、カラムはテーブルです。ってきたことをここではoracle、mysqlです。テーブルを作成し、コピー&ペーストの一部i18nデータ入で、何が起こるか見てみてください...が設定されてい..
るのは僕が完全に忘れですか?
編集:
ますます明示的な...私は、通常行三列のテーブ---言語,key,value...が"価値"を含む潜在的に外国語の単語またはフレーズ..."言語"の一言語キーの"キー"は、英語キー(ログインします。エラーになります。パスワードになります。dup)...言語とキーインデックスが付き...
私はその構築にインタフェースは、このような構造を示す各キーのすべての翻訳(値)...きゃび監査トレイル、"汚染"マーカーおよびその他のものに必要なものを翻訳者は、データ入力の民俗を使用することが出来ます。..
編集2:
これで、追加の情報のJSTLタグを理解しているビールのおつまみことがなかったわっ..ったこの古い情報 theserverside...
HttpSession session = .. [get hold of the session]
ResourceBundle bundle = new PropertyResourceBundle(toInputStream(myOwnProperties)) [toInputStream just stores the properties into an inputstream]
Locale locale = .. [get hold of the locale]
javax.servlet.jsp.jstl.core.Config.set(session, Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(bundle ,locale));
他のヒント
だそして私はこの作danbの助けます。
このリソースバンドルクラスおよびリソースバンドル制御クラスです。
このコードから@[danb]'s.
ResourceBundle bundle = ResourceBundle.getBundle("AwesomeBundle", locale, DbResourceBundle.getMyControl());
javax.servlet.jsp.jstl.core.Config.set(actionBeanContext.getRequest(), Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(bundle, locale));
んが、このクラスです。
public class DbResourceBundle extends ResourceBundle
{
private Properties properties;
public DbResourceBundle(Properties inProperties)
{
properties = inProperties;
}
@Override
@SuppressWarnings(value = { "unchecked" })
public Enumeration<String> getKeys()
{
return properties != null ? ((Enumeration<String>) properties.propertyNames()) : null;
}
@Override
protected Object handleGetObject(String key)
{
return properties.getProperty(key);
}
public static ResourceBundle.Control getMyControl()
{
return new ResourceBundle.Control()
{
@Override
public List<String> getFormats(String baseName)
{
if (baseName == null)
{
throw new NullPointerException();
}
return Arrays.asList("db");
}
@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException,
InstantiationException, IOException
{
if ((baseName == null) || (locale == null) || (format == null) || (loader == null))
throw new NullPointerException();
ResourceBundle bundle = null;
if (format.equals("db"))
{
Properties p = new Properties();
DataSource ds = (DataSource) ContextFactory.getApplicationContext().getBean("clinicalDataSource");
Connection con = null;
Statement s = null;
ResultSet rs = null;
try
{
con = ds.getConnection();
StringBuilder query = new StringBuilder();
query.append("select label, value from i18n where bundle='" + StringEscapeUtils.escapeSql(baseName) + "' ");
if (locale != null)
{
if (StringUtils.isNotBlank(locale.getCountry()))
{
query.append("and country='" + escapeSql(locale.getCountry()) + "' ");
}
if (StringUtils.isNotBlank(locale.getLanguage()))
{
query.append("and language='" + escapeSql(locale.getLanguage()) + "' ");
}
if (StringUtils.isNotBlank(locale.getVariant()))
{
query.append("and variant='" + escapeSql(locale.getVariant()) + "' ");
}
}
s = con.createStatement();
rs = s.executeQuery(query.toString());
while (rs.next())
{
p.setProperty(rs.getString(1), rs.getString(2));
}
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException("Can not build properties: " + e);
}
finally
{
DbUtils.closeQuietly(con, s, rs);
}
bundle = new DbResourceBundle(p);
}
return bundle;
}
@Override
public long getTimeToLive(String baseName, Locale locale)
{
return 1000 * 60 * 30;
}
@Override
public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, long loadTime)
{
return true;
}
};
}
してデータベースのテーブルとキー/言語/期間が鍵となるのはnを整数とする複合主キーと一緒に。
また、祖、そし書面に独自の PropertyMessageResources 実施できるように <bean:message key="impressum.text" />
.
で非常に柔軟な動的にスイッチの言語のフロントエンドと更新の翻訳ができます。
ActulyうScArcher2必要がdavids対応するには付いておりませんので、訂正または詳細
の解ScArcher2を選びましたがimo恐mestake:)負荷の全ての翻訳は一時間---任意の大き応募さんを殺します。荷thousendsの翻訳の申請ごとに...
デヴィッドの方法が多用されているのに実際の生産環境です。時限dbの通話は、毎にメッセージを翻訳できるグループの作成の翻訳による話題の、機能性等にをプリロードします。これはもう少し複雑で、置き換えることもできますの良いキャッシュシステム。