GithubHelp home page GithubHelp logo

macourtney / clj-internationalization Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 160 KB

Another internationalization library for clojure. clj-internationalization reads a resource bundle and generates functions for each key.

Clojure 100.00%

clj-internationalization's Introduction

clj-internationalization

Another internationalization library for clojure. clj-internationalization reads a resource bundle and generates functions for each key.

Usage

First add a properties file named Terms.properties to your classpath or resource path.

Add your terms to Terms.properties, for example:

TEST_TERM = test term

To use the term, simply import the clj-internationalization.core and call the generated function for it:

(require [clj-internationalization.term :as term])

(term/test-term)

Clj-internationalization also supports parameterization. For example, the following parameterized term:

TEST_PARAMETER = test {0} parameter

Can be passed a parameter like:

(term/test-parameter "blah")

Which results in the string:

"test blah parameter"

Creating your own terms namespace

If you want to use your own terms namespace, or want to use a properties file other than Terms.properties file, you will need to create your own namespace in the following way:

Assuming you want to use the namespace, my-terms and the bundle MyTerms.properties, start by creating a my_terms.clj file in the appropriate place in your project.

Your ns description should look like:

(ns my-terms
  (:refer-clojure :only [])
  (:require [clj-internationalization.core :as core]))

The above ns call removes all clojure core symbols from the namespace and requires the clj-internationalization.core namespace. The clojure core symbols were removed to keep name collisions from occurring. You'll need clj-internationalization.core to load your properties file into your namespace.

All you need to do now is load the properties file with the following command:

(core/load-terms "MyTerms")

The above function call finds the properties file for MyTerms and loads all of the term functions in to the current namespace.

Your full my_terms.clj file should look like:

(ns my-terms
  (:refer-clojure :only [])
  (:require [clj-internationalization.core :as core]))

(core/load-terms "MyTerms")

clj-internationalization's People

Contributors

macourtney avatar

Stargazers

Jonathan McHugh avatar Pete Doherty avatar Nicola Mometto avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

elais

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.