Skip to content

Commit

Permalink
Merge pull request #10 from MortenDHansen/add-cache-heater
Browse files Browse the repository at this point in the history
Do not create groups from paragraphs
  • Loading branch information
MortenDHansen authored Mar 9, 2022
2 parents 1de0b7f + 3244d7b commit 046a92e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/DatabaseTranslationsTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ public function get($key, array $replace = [], $locale = null, $fallback = true)
$group = '*';
}

// The group should be just a word. Sometimes translation key is an entire paragraph. We put that into ungrouped
if (!(preg_match('/^[\pL\pM\pN_-]+$/u', $group) > 0)) {
$group = '*';
$item = $key;
}

if (!array_key_exists($item, $this->loadedFromDb['*'][$group][$passedLocale])) {
$this->createMissingKey($group, $item, $passedLocale);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Feature/DatabaseTranslationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,15 @@ public function itCreatesMissingKeysInDifferentLocales()
$this->assertDatabaseHas('database_lang_items', ['group' => '*', 'key' => 'color', 'locale' => 'de']);
}

/**
* @test
* @return void
*/
public function itCanHandleChunksOfText()
{
__("Sometimes, translations are in fact a chunk of text. It can be very long and it makes no sense to treat it as a grouped key.");
$this->assertEquals('*', DatabaseLangItem::all()->first()->group);
}


}

0 comments on commit 046a92e

Please sign in to comment.