Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding formatting examples to README #6

Merged
merged 4 commits into from
Mar 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ echo Locale::fromCountrySlashLanguage('ca/fr'); // fr_CA

```

### Formatting

Use:

- `%L` For uppercase language code
- `%l` For lowercase language code
- `%C` For uppercase country code
- `%c` For lowercase country code

Note:

- any other combination of %{:char:} will throw an InvalidArgumentException unless the % is escaped with \
- to get a `\` You will need to double escape ( `\\\` )

Examples:

```php
echo Locale::fromString('se_FI')->format('%L_%c'); // SE_fi
echo Locale::fromString('se_FI')->format('%C/%s'); // FI/se
echo Locale::fromString('se_FI')->format('%c/%s'); // fi/se
echo Locale::fromString('se_FI')->format('%c\\\%s'); // fi\se
```

## Installation

```
Expand Down
15 changes: 7 additions & 8 deletions src/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,15 @@ public static function fromCountrySlashLanguage($countrySlashLanguage)
}

/**
* From countryCode/languageCode
* Format Locale as string
*
* echo Locale::fromString('se_FI')->format('%L_%c'); // SE_fi
* echo Locale::fromString('se_FI')->format('%C/%s'); // FI/se
* echo Locale::fromString('se_FI')->format('%c/%s'); // fi/se
* echo Locale::fromString('se_FI')->format('%c\\\%s'); // fi\se
*
* The use of this code is as follows:
* $locale = Locale::fromString('se_FI');
* 'SE_fi' == $locale->format('%L_%c');
* 'FI/se' == $locale->format('%C/%s');
* 'fi/se' == $locale->format('%c/%s');
* 'fi\se' == $locale->format('%c\\\%s');
* Current formatting codes are:
*
* Current translattable codes are:
* * %L For uppercase language code
* * %l For lowercase language code
* * %C For uppercase country code
Expand Down