ISIS-903: refactoring in the direction of also reading .po files
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/bc5f87bf Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/bc5f87bf Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/bc5f87bf Branch: refs/heads/master Commit: bc5f87bf79134530365e9fc0f9be5361cd9b698b Parents: 759e322 Author: Dan Haywood <[email protected]> Authored: Fri Feb 13 18:58:05 2015 +0000 Committer: Dan Haywood <[email protected]> Committed: Wed Feb 18 14:07:32 2015 +0000 ---------------------------------------------------------------------- .../services/i18n/po/TranslationServicePo.java | 87 ++++++++++++++++++++ 1 file changed, 87 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/bc5f87bf/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/i18n/po/TranslationServicePo.java ---------------------------------------------------------------------- diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/i18n/po/TranslationServicePo.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/i18n/po/TranslationServicePo.java new file mode 100644 index 0000000..a5b012d --- /dev/null +++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/i18n/po/TranslationServicePo.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.isis.core.metamodel.services.i18n.po; + +import java.util.Locale; +import java.util.Map; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.isis.applib.annotation.Programmatic; +import org.apache.isis.applib.services.i18n.TranslationService; + +/** + * Not annotated with @DomainService, but is registered as a fallback by <tt>ServicesInstallerFallback</tt>. + */ +public class TranslationServicePo implements TranslationService { + + public static Logger LOG = LoggerFactory.getLogger(TranslationServicePo.class); + + private boolean prototype; + + private PoAbstract po; + + public TranslationServicePo() { + po = new PotWriter(this); + } + + //region > init, shutdown + + @Programmatic + @PostConstruct + public void init(final Map<String,String> config) { + final String deploymentType = config.get("isis.deploymentType"); + prototype = deploymentType.toLowerCase().contains("prototype"); + + if (!prototype) { + po = new PoReader(this); + } + po.init(config); + } + + @Programmatic + @PreDestroy + public void shutdown() { + po.shutdown(); + } + //endregion + + boolean isPrototype() { + return prototype; + } + + + @Override + @Programmatic + public String translate(final String context, final String originalText, final Locale targetLocale) { + return po.translate(context, originalText, targetLocale); + } + + /** + * Not API + */ + public String toPo() { + if (!prototype) { + throw new IllegalStateException("Not in prototype mode"); + } + return ((PotWriter)po).toPo(); + } + +}
