Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

messagevisor-example-java

A small Java application using the published Messagevisor Java SDK.

It fetches a production datafile from the Messagevisor Cloudflare Pages example, creates a Messagevisor instance, and evaluates plain and ICU formatted translations.

Learn more at messagevisor.com.

Requirements

  • Java 17 or newer
  • Maven 3.9 or newer
  • A GitHub account and token with the read:packages scope

GitHub Packages authentication

Messagevisor Java is published through GitHub Packages. GitHub requires authentication when downloading Maven packages, including public packages.

Create ~/.m2/settings.xml with your GitHub username and a personal access token with the read:packages scope:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>github</id>
      <username>YOUR_GITHUB_USERNAME</username>
      <password>YOUR_GITHUB_TOKEN</password>
    </server>
  </servers>
</settings>

Create a token at github.com/settings/tokens.

The GitHub Actions workflow uses its repository GITHUB_TOKEN. After creating the messagevisor-example-java repository, grant it read access under the Actions access settings for both published Messagevisor Java packages.

Build and test

make build

This compiles the application, runs its unit test, and creates an executable JAR in target/.

Run

make run

The application fetches this datafile by default:

https://messagevisor-example-cloudflare-pages.pages.dev/production/messagevisor-web-en-US.json

You can provide another Messagevisor datafile URL as the first argument:

mvn exec:java -Dexec.args="https://example.com/messagevisor-web-en-US.json"

You can also run the packaged application:

java -jar target/messagevisor-example-java-1.0.0.jar

The example uses:

  • com.messagevisor:messagevisor-sdk:0.2.0
  • com.messagevisor:messagevisor-module-icu:0.2.0

Example output

Datafile: https://messagevisor-example-cloudflare-pages.pages.dev/production/messagevisor-web-en-US.json
Locale: en-US
Target: web
Revision: 2

auth.signin: Sign in
nav.home: Home
nav.contact: Contact us before 5:30 PM

The exact localized time output can differ slightly with the CLDR data provided by the installed Java runtime.

Related project

The served datafile is authored and deployed by messagevisor-example-cloudflare-pages.

License

MIT

About

Example application using Java SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages