Skip to content

Commit

Permalink
Merge pull request #152 from mcamara/development
Browse files Browse the repository at this point in the history
Version 0.15
Added tests
Changed functions (check README)
Refactoring
  • Loading branch information
Marc Cámara committed Nov 13, 2014
2 parents 41a24af + 20d39d6 commit 29dcd27
Show file tree
Hide file tree
Showing 8 changed files with 1,242 additions and 476 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 0.15.0
- Added tests from scratch
- Refactored multiple functions
- getLocalizedURL now accepts attributes for the url (if needed)
- $routeName is always a string, no need to be an array if it just have the translation key for the current url

### 0.14.0
- Laravel 4.2 compatibility
- Removed Laravel 4.0 compatibility
Expand Down
103 changes: 54 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Easy i18n localization for Laravel 4, an useful tool to combine with Laravel loc

Add Laravel Localization to your `composer.json` file.

"mcamara/laravel-localization": "0.14.*"
"mcamara/laravel-localization": "0.15.*"

Run `composer install` to get the latest version of the package.

If you are using a laravel version lower than 4.2, you should use 0.13.* version.
If you are using a laravel version lower than 4.2, you should use 0.13.* version. Moreover, 0.15 version will be the last one with support for Laravel 4.2. A new version compatible with Laravel 5 is in development and would be available soon after the final version of Laravel is released, labeled as version 1.x .

### Manually

Expand Down Expand Up @@ -137,74 +137,63 @@ If you want to hide the default locale but always show other locales in the url,

This package comes with some useful functions, like:

### Get Clean routes
### Get URL for an specific locale

```php
/**
* It returns an URL without locale (if it has it)
*
* @param string $url URL to clean, if false, current url would be taken
*
* @return string URL with no locale in path
*/
public function getNonLocalizedURL($url = null)
* Returns an URL adapted to $locale
*
* @param string|boolean $locale Locale to adapt, false to remove locale
* @param string|false $url URL to adapt in the current language. If not passed, the current url would be taken.
* @param array $attributes Attributes to add to the route, if empty, the system would try to extract them from the url.
*
* @throws UnsupportedLocaleException
*
* @return string|false URL translated, False if url does not exist
*/
public function getLocalizedURL($locale = null, $url = null, $attributes = array())

//Should be called in a view like this:
{{ LaravelLocalization::getNonLocalizedURL(optional string $url) }}
{{ LaravelLocalization::getLocalizedURL(optional string $locale, optional string $url, optional array $attributes) }}
```

It returns a URL clean of any localization.
It returns a URL localized to the desired locale.

### Get URL for an specific locale, there are two options here
### Get Clean routes

```php
/**
* Returns an URL adapted to $locale
*
* @param string $locale Locale to adapt
* @param string $url URL to adapt. If not passed, the current url would be taken
*
* @throws UnsupportedLocaleException
*
* @return string URL translated
*/
public function getLocalizedURL($locale, $url = null)
/**
* It returns an URL without locale (if it has it)
* Convenience function wrapping getLocalizedURL(false)
*
* @param string|false $url URL to clean, if false, current url would be taken
*
* @return string URL with no locale in path
*/
public function getNonLocalizedURL($url = null)

//Should be called in a view like this:
{{ LaravelLocalization::getLocalizedURL(string $locale, optional string $url) }}
{{ LaravelLocalization::getNonLocalizedURL(optional string $url) }}
```

or

```php
/**
* Returns an URL adapted to $locale or current locale
*
* @param string $url URL to adapt. If not passed, the current url would be taken.
* @param string|boolean $locale Locale to adapt, false to remove locale
*
* @throws UnsupportedLocaleException
*
* @return string URL translated
*/
public function localizeURL($url, $locale = null)
```
It returns a URL clean of any localization.

It returns a URL localized to the desired locale.

### Get URL for an specific translation key

```php
/**
* Returns an URL adapted to the route name and the locale given
*
* @param string $locale Locale to adapt
* @param array $transKeyNames Array containing the Translation key name of the url to adapt
* @param array $attributes Attributes for the route (only needed if transKeyName needs them)
* Returns an URL adapted to the route name and the locale given
*
* @throws UnsupportedLocaleException
*
* @return string|boolean URL translated
*/
public function getURLFromRouteNameTranslated($locale, $transKeyNames = array(), $attributes = array())
* @param string|boolean $locale Locale to adapt
* @param string $transKeyName Translation key name of the url to adapt
* @param array $attributes Attributes for the route (only needed if transKeyName needs them)
*
* @return string|false URL translated
*/
public function getURLFromRouteNameTranslated($locale, $transKeyName, $attributes = array())

//Should be called in a view like this:
{{ LaravelLocalization::getURLFromRouteNameTranslated(string $locale, optional array $transKeyNames, optional array $attributes) }}
Expand All @@ -228,6 +217,22 @@ It returns a route, localized to the desired locale using the locale passed. If

This function will return all supported locales and their properties as an array.

### Get Supported Locales Keys

```php
/**
* Returns supported languages language key
*
* @return array keys of supported languages
*/
public function getSupportedLanguagesKeys()

//Should be called like this:
{{ LaravelLocalization::getSupportedLanguagesKeys() }}
```

This function will return an array with all the keys for the supported locales.

### Set Locale

```php
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": ["localization", "laravel", "php"],
"homepage": "https://github.com/mcamara/laravel-localization",
"license": "MIT",
"version": "0.14.9",
"version": "0.15.0",
"authors": [
{
"name": "Marc Cámara",
Expand Down
Loading

0 comments on commit 29dcd27

Please sign in to comment.