Giter Site home page Giter Site logo

play-i18n-url's Introduction

Play URL Path Base Internationalization (I18n)

!! THIS IS UNDER DEVELOPMENT !!

This is a request handler for play framework Scala. It handles the request path for all play default router to use internationalized path as the language tag, and resets Accept-Language.

http://example.com
http://example.com/en-US

If you find any weird behavior or bugs please report or issue me :) I always welcome your pull requests!

Installation

Dependency

Add those resolver and dependency to build.sbt:
Currently it only supports Play Framework 2.5.x

// Adding resolver
resolvers += "EJISAN" at "https://ejisan.github.io/repo/"
// Adding dependency
libraryDependencies += "com.ejisan" %% "play-i18n-url" % "1.0.0-SNAPSHOT"

Uses

  1. Add the request handler (conf/application.conf)
play.http {
  requestHandler = "ejisan.play.i18n.UrlI18nRequestHandler"
}
  1. Add the application languages (conf/application.conf)
    The format of the languages must fallow Language Tag Syntax which is defined in RFC5646.
play.i18n {
  # The application languages
  langs = [ "en-US", "es-US", "ja-JP", "en-JP" ]
  ...
  1. Your application is ready!
    UrlI18nRequestHandler will automatically add language tag at the head of the requested path and set to Accept-Language. If the language tag in the requested path is case insensitive, UrlI18nRequestHandler replaces it as right case and redirects it.
# http://example.com/en-US or http://example.com/ja-JP etc
GET     /                     controllers.Controller.index
# http://example.com/en-US/page1 or http://example.com/ja-JP/page1 etc
GET     /page1                controllers.Controller.page1

Sird router with Non-Internationalized Routing

Check about sird router

import javax.inject.Inject
import play.api.http.{ HttpErrorHandler, HttpConfiguration }
import play.api.i18n.DefaultLangs
import play.api.mvc._
import play.api.routing._
import play.api.routing.sird._
import ejisan.play.i18n.{ UrlI18nRequestHandler, ScalaSirdRouterSupport }

class MyUrlI18nRequestHandler @Inject()(
  langs: DefaultLangs,
  defaultRouter: Router,
  errorHandler: HttpErrorHandler,
  httpConfiguration: HttpConfiguration)
  extends UrlI18nRequestHandler(langs, defaultRouter, errorHandler, httpConfiguration)
  with ScalaSirdRouterSupport {
  // Using a sird router
  def router: Router = Router.from {
    case GET(p"/") => Action {
      Results.Ok("Hello Play!")
    }
  }
}

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.