Skip to content

Commit

Permalink
✨ Add language mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Mar 5, 2021
1 parent 033e588 commit e7783d8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Classes/Fusion/Implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

class Implementation extends AbstractFusionObject
{
/**
* @Flow\InjectConfiguration()
* @var array
*/
protected $settings;

/**
* @Flow\Inject
* @var Environment
Expand Down Expand Up @@ -84,6 +90,10 @@ public function evaluate()

$language = str_replace('_', '-', strtolower($this->getLocale()));

if (isset($this->settings['mapping'][$language]) && is_string($this->settings['mapping'][$language])) {
$language = $this->settings['mapping'][$language];
}

if (!$this->texFileExists($language)) {
$firstPartOfLanguage = explode('-', $language)[0];
if ($firstPartOfLanguage === $language) {
Expand Down
6 changes: 6 additions & 0 deletions Configuration/Settings.Carbon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Carbon:
Hyphen:
mapping:
en: en-gb
de-de: de
de-at: de
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ prototype(Foo.Bar:Component) {

**throwException** (boolean, default = `true`) : Throw exception if no hyphen definition is found

## Custom language mappings

Probably you've got a language defined that is not available in syllable. For example, `en` is not available, but `en-gb` is. Because of that, you can map your language preset to another syllable language: Per default following settings are set in [Settings.Carbon.yaml]:

```yaml
Carbon:
Hyphen:
mapping:
en: en-gb
de-de: de
de-at: de
```
## Credits
This implementation was heavily inspired by [packagefactory/hyphenate].
Expand All @@ -89,4 +102,5 @@ This implementation was heavily inspired by [packagefactory/hyphenate].
[subscription]: https://github.com/CarbonPackages/Carbon.Hyphen/subscription
[phpsyllable]: https://github.com/vanderlee/phpSyllable
[syllable languages]: https://github.com/vanderlee/phpSyllable/tree/master/languages
[settings.carbon.yaml]: Configuration/Settings.Carbon.yaml
[packagefactory/hyphenate]: https://github.com/PackageFactory/hyphenate

0 comments on commit e7783d8

Please sign in to comment.