Closed nestordedios closed 4 years ago
My guess is that this has to do with the strict check that hasItem
does, while has
is more naive IIRC.
The specific parts for hasItem are: https://github.com/bolt/collection/blob/9ef5a76e4b417d16adb5850cfe5cc93ed1903e2c/src/Bag.php#L180-L192
And for has: https://github.com/bolt/collection/blob/9ef5a76e4b417d16adb5850cfe5cc93ed1903e2c/src/Bag.php#L149-L159
Yes, hasItem
needs to be has
.
The code wants to check whether a key for a label has been defined.
As pointed out above. Given:
$label1 : {
$language1: $translation1,
$language2: $translation2
},
hasItem
does not check $label1
key, but the { $lang1: ... }
value instead.has
function correctly checks for array keys only.This function is called in the twigL
function and is supposed to add labels if they don't exist yet. However, every time a label+language combination's value is empty, all the translations for that label will be wiped.
There's another hasItem
check that needs to be changed. It's basically the same check. I made a new PR with this addition: #65
Initially, I thought the whole labels.json
would be wiped, but it's only for labels with non-existent translations.
NOTE: I still don't know why it happens with one of my projects that has both translations filled in and still get wiped.
Fixes #61
It seems hasItem($label) always returns false and the check on line 117 https://github.com/BoltTranslate/labels/blob/master/src/Labels.php#L117 never evaluates to true.
Then translated labels are being reset on line 121 https://github.com/BoltTranslate/labels/blob/master/src/Labels.php#L121