문제

을 사용하고 싶은 데이터베이스를 저장 i18n 키/값 쌍으로 할 수 있도록 우리가 수정/다 i18n 데이터 수 있습니다.누군가 이렇?또는 사람의 아이디어를 구현하는 방법을 이?내가 읽은 여러 스레드에서 이지만,나는 보지 못했 실행할 수 있는 솔루션입니다.

저는 특별히 참조하는 것이 뭔가와 함께 작동 jstl 같은 태그가

<fmt:setlocale>
<fmt:bundle>
<fmt:setBundle>
<fmt:message>

나는 생각이 포함됩니다장 resourcebundle 을도 사용할 수 있지만 이런 문제에 부딪쳤었던 방법으로 할 수 jstl 태그를 얻을 리소스입니다.

도움이 되었습니까?

해결책

당신은 단지 요구를 저장하는 방법 UTF-8/16 문자에서 DB?mysql 그것은 단지 문제의 확인을 구축 UTF8 지원하고 설정하는 기본값으로,또는 지정하에서 열 또는 테이블 수준입니다.나는 이것에서 오라클 및 mysql 다.테이블을 만들과 잘라고 붙여넣는 일부 i18n 데이터로 무슨 일이 일어나는지 볼 수 있...당신은 설정할 수 있습미..

또는 나는 완전히 누락 포인트는?

편집:

더 명시적...나는 일반적으로 구현한 세 개의 열이다.언어 key,value...여기서"value"담 잠재적으로 외국어 단어나 문장..."언어"일부가 포함되어 열쇠고"열쇠"를 영어 키(i.e로그인합니다.오류가 있습니다.암호입니다.dup)...언어 및 주요 인덱싱...

나는 그러한 인터페이스 구조에 이처럼 보이는 각각의 키로 모든 그 번역이(가)...그것은 것을 얻을 수 있습니다 포함한 감사 추적 및"더러운"마커와는 다른 모든 물건을 사용하도록 설정해야는 번역하고 데이터 입력 민속 그것을 사용하기 위해..

Edit2:

이제는 당신이 추가 정보에 대해 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 필요한 데이비드 반응하는 표시되지 않은 올바른 또는 helpfull.

솔루션 ScArcher2 선택하여 사용하는 imo 끔찍한 mestake:)로딩이 모든 번역을 한번에...에서 어떤 큰 응용 프로그램의 죽습니다.선적 thousends 번역의 각 요청을...

다윗의 방법은 더 많은 일반적으로 사용되는 실제 프로덕션 환경에서.때로는 한계 db 통화는 모든 메시지 번역,당신 그룹을 만들 수 있는 번역의 항목,기능 등입니다.미리 로드하는 그들.하지만 이것이 조금 더 복잡하고 대체할 수 있으로 좋은 캐시 시스템입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top