Skip to content

Commit c5f789f

Browse files
deemonicclaude
andcommitted
fix: resolve language switching not loading correct profanities
- Update ConfigurationLoader::load() to accept language parameter - Fix BlaspService constructor to set chosenLanguage before loading config - Ensure language switching properly reloads configuration with target language - Language detection now works correctly: Blasp::spanish()->check('mierda') detects profanity - All 184 tests still passing with multi-language detection working 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6969ff7 commit c5f789f

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/BlaspService.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,20 @@ public function __construct(
105105
?ConfigurationLoader $configurationLoader = null
106106
) {
107107
$this->configurationLoader = $configurationLoader ?? new ConfigurationLoader();
108-
$this->config = $this->configurationLoader->load($profanities, $falsePositives);
108+
109+
// Set default language from config if not specified
110+
if (!$this->chosenLanguage) {
111+
$this->chosenLanguage = config('blasp.default_language', 'english');
112+
}
113+
114+
$this->config = $this->configurationLoader->load($profanities, $falsePositives, $this->chosenLanguage);
109115

110116
$this->profanityDetector = new ProfanityDetector(
111117
$this->config->getProfanityExpressions(),
112118
$this->config->getFalsePositives()
113119
);
114120

115121
$this->stringNormalizer = Normalize::getLanguageNormalizerInstance();
116-
117-
// Set default language from config if not specified
118-
if (!$this->chosenLanguage) {
119-
$this->chosenLanguage = config('blasp.default_language', 'english');
120-
}
121122
}
122123

123124
/**

src/Config/ConfigurationLoader.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@ public function __construct(
3131
*
3232
* @param array|null $customProfanities
3333
* @param array|null $customFalsePositives
34+
* @param string|null $language
3435
* @return DetectionConfigInterface
3536
*/
36-
public function load(?array $customProfanities = null, ?array $customFalsePositives = null): DetectionConfigInterface
37+
public function load(?array $customProfanities = null, ?array $customFalsePositives = null, ?string $language = null): DetectionConfigInterface
3738
{
38-
// Try to load from English language file first, fall back to config if that fails
39+
// Determine which language to load
40+
$targetLanguage = $language ?? config('blasp.default_language', 'english');
41+
3942
$profanities = $customProfanities;
4043
$falsePositives = $customFalsePositives;
4144

4245
if ($profanities === null) {
4346
try {
44-
$englishData = $this->loadLanguage('english');
45-
$profanities = $englishData['profanities'] ?? [];
47+
$languageData = $this->loadLanguage($targetLanguage);
48+
$profanities = $languageData['profanities'] ?? [];
4649
if (empty($profanities)) {
47-
throw new \Exception('No profanities found in English language file');
50+
throw new \Exception("No profanities found in {$targetLanguage} language file");
4851
}
4952
} catch (\Exception $e) {
5053
// Fall back to config file
@@ -54,8 +57,8 @@ public function load(?array $customProfanities = null, ?array $customFalsePositi
5457

5558
if ($falsePositives === null) {
5659
try {
57-
$englishData = $this->loadLanguage('english');
58-
$falsePositives = $englishData['false_positives'] ?? [];
60+
$languageData = $this->loadLanguage($targetLanguage);
61+
$falsePositives = $languageData['false_positives'] ?? [];
5962
} catch (\Exception $e) {
6063
// Fall back to config file
6164
$falsePositives = config('blasp.false_positives');

0 commit comments

Comments
 (0)