Coder Social home page Coder Social logo

phoenix_linguist's Introduction

Build Status

PhoenixLinguist

A project that integrates Phoenix with Linguist, providing a plug and view helpers

PhoenixLinguistPlug checks if there's a :locale param on the requested route, if there is and matches the existing locales, puts the locale on the session. If the requested :locale does not exist, forwards the user to the ErrorView 404 handler defined. If there isn't a :locale defined, PhoenixLinguistPlug puts the default locale on the session PhoenixLinguist.Helpers are a couple of view helpers that can be used on templates to help determine user's prefered locale

You can see the online documentation for more information.

Requirements

Elixir 1.0.2

Phoenix 0.10.0

Instructions

Define your I18n Module on config.ex next to other Endpoint Settings

config :my_app, MyApp.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "l6M/YRIzkiqMk5Irn9UNm7ANo1BoHIF0XchxNmcUJWhdKZdERA45ASDFIxZ",
  debug_errors: false,
  i18n: MyApp.I18n

Add PhoenixLinguist.Plug to the plug list on your routes file, on the browser pipeline after Phoenix plugs

  pipeline :browser do
    plug :accepts, ~w(html)
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug PhoenixLinguist.Plug
  end

If you need to use the helper functions, add PhoenixLinguist.Helpers to your web module:

  def view do
    quote do
      use Phoenix.View, root: "web/templates"

      import MyAPP.Router.Helpers
      use Phoenix.HTML
      import PhoenixLinguist.Helpers
    end
  end

Check the online documentation for the list of helpers available

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.