Coder Social home page Coder Social logo

jpnforphp's Introduction

#JpnForPhp build status Stories in Ready Bitdeli Badge

A tiny PHP lib which provides nice functions & wrappers to interact with Japanese language. [Official Website]

##Installation

The recommended way to install JpnForPhp is through Composer. Just create a composer.json file and run the php composer.phar install command to install it:

{
    "require": {
        "mbilbille/jpnforphp": "~0.5"
    }
}

##Tests

To run the test suite, you need Composer:

    $ php composer.phar install --dev
    $ vendor/bin/phpunit

##Features list Provides the following components:

  • Helper: a set of function to help you interact with Japanese wordings (split, extract, clean, etc.).
  • Analyzer: various "inspecting" functions (length, count kana, etc.).
  • Transliterator: handle both transliterations roman to kana and kana to roman (support all mainstream romanization systems).

##Usage

###Helper component:

use JpnForPhp\Helper\Helper;

Helper::split('素晴らしいでしょう'); // array('素','晴','ら','し','い','で','す')
Helper::subString('素晴らしいでしょう', 2, 4); // 'らし'
Helper::extractKanji('素晴らしいでしょう'); // array('素晴')
Helper::extractHiragana('素晴らしいでしょう', 1, true); // array('ら','し','い','で','しょ','う')

###Analyzer component

use JpnForPhp\Analyzer\Analyzer;

Analyzer::length('素晴らしいです'); // 7
Analyzer::inspect('素晴らしいです'); // array('length'=>7,'kanji'=>2,'hiragana' =>5,'katakana'=>0)
Analyzer::countHiragana('素晴らしいです'); // 5
Analyzer::hasKanji('素晴らしいです'); // TRUE

###Transliterator component:

use JpnForPhp\Transliterator\Romaji;
use JpnForPhp\Transliterator\Kana;

$hepburn = new Romaji();
$kunrei = new Romaji('kunrei');
$hiragana = new Kana('hiragana');
$katakana = new Kana('katakana');

$hepburn->transliterate('ローマジ で かいて'); // rōmaji de kaite
$kunrei->transliterate('ローマジ で かいて'); // rômazi de kaite
$hiragana->transliterate('kana de kaite'); // かな で かいて
$katakana->transliterate('kana de kaite'); // カナ デ カイテ

Starting from the version 0.5, all the transliteration workflow is defined in .yaml file.

Romaji.php and Kana.php provides a wild range of functions which can be used to define your own transliteration system. Here is a sample .yaml file

id: mySystem
name:
    english: "My romanization system"
    japanese: "マイローマ字"
workflow:
    - function: transliterateDefaultCharacters
      parameters:
            mapping:
                : a
                : i
                // [...]
                : po
                : pu
    - function: transliterateSokuon
      parameters:
            default: true
            hepburn: false
    - function: transliterateChoonpu
      parameters:
        macrons:
            a: aa
            i: ii
            u: uu
            e: ee
            o: oo

JpnForPhp supports the following standard transliteration system:

.yaml files for those transliteration systems are available here:

##Upcoming

Check out the develop branch to get all the latest code and change (http://github.com/mbilbille/jpnforphp/tree/develop)

License

JpnForPHP was created by Matthieu Bilbille and released under the MIT License.

##Integration

  • JPNlizer integrates JpnForPhp into Drupal - sandbox project [Deprecated]
  • JpnForPhpBundle: integrates JpnForPhp as a Symfony2 Bundle - JpnForPhpBundle (by @albertofem)

Sponsored by Openjisho.com.

jpnforphp's People

Contributors

mbilbille avatar akeru avatar albertofem avatar rumpl avatar waffle-with-pears avatar

Watchers

James Cloos avatar Hưng Trịnh avatar

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.