如何在jhorstmann-i18n上创建po文件?

时间:2018-11-02 03:26:11

标签: java internationalization

我计划在Java应用程序中开发i18n。现在,我发现了两个有用的库来解决此问题(awkayjhorstmann)。我通过使用awkay创建了一个有关i18n的简单示例而获得成功(他们提供了一个示例)。但我无法使用jhorstmann来创建它(我看不到有关它的文档/样本)。所以我的问题是如何使用该库创建示例Java应用程序项目,并告诉我如何生成po文件?

代码

package com.khmerdev.jhorstmannTesti18n;

import net.jhorstmann.i18n.I18N;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        System.out.println(I18N.tr("Hello World!"));
    }
}

POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.khmerdev</groupId>
  <artifactId>jhorstmannTesti18n</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>jhorstmannTesti18n</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  <build>
    <resources>
        <resource>
            <directory>resources/META-INF/services</directory>
        </resource>
    </resources>
    <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>org.sanusb.view.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.jhorstmann</groupId>
                <artifactId>i18n-maven-plugin</artifactId>
                <version>0.2</version>
                <configuration>
                    <targetBundle>com.khmerdev.jhorstmannTesti18n.Messages</targetBundle>
                    <outputFormat>class</outputFormat>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>dist</goal>
                        </goals>
                        <phase>generate-resources</phase>
                    </execution>
                </executions>
            </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>net.jhorstmann</groupId>
            <artifactId>i18n-core</artifactId>
            <version>0.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>net.jhorstmann</groupId>
            <artifactId>i18n-gettext-tools</artifactId>
            <version>0.2</version>
        </dependency>
  </dependencies>
</project>

登录

Hello World!
Exception in thread "main" java.lang.NullPointerException
    at java.util.ResourceBundle$CacheKey.calculateHashCode(Unknown Source)
    at java.util.ResourceBundle$CacheKey.<init>(Unknown Source)
    at java.util.ResourceBundle.getBundleImpl(Unknown Source)
    at java.util.ResourceBundle.getBundle(Unknown Source)
    at net.jhorstmann.i18n.impl.DefaultResourceBundleProviderFactory$DefaultResourceBundleProvider.getResourceBundle(DefaultResourceBundleProviderFactory.java:21)
    at net.jhorstmann.i18n.I18N.getBundle(I18N.java:40)
    at net.jhorstmann.i18n.I18N.getBundle(I18N.java:45)
    at net.jhorstmann.i18n.I18N.tr(I18N.java:123)
    at com.khmerdev.jhorstmannTesti18n.App.main(App.java:14)

0 个答案:

没有答案