diff --git a/auto_tag_plugin/auto_tag_plugin.php b/auto_tag_plugin/auto_tag_plugin.php index 42cafbe..edbaa25 100644 --- a/auto_tag_plugin/auto_tag_plugin.php +++ b/auto_tag_plugin/auto_tag_plugin.php @@ -4,7 +4,7 @@ use Shaarli\Config\ConfigManager; function auto_tag_plugin_init(ConfigManager $conf) { - // Configuration des mots-clés et tags correspondant aux règles fournies + // Configure keywords and tags based on provided rules $conf->setEmpty('plugins.AUTO_TAG_KEYWORDS', [ 'accessibility,web development,web design,html,css' => 'web-development', 'adhd,tdah' => 'adhd', @@ -108,7 +108,7 @@ function fetch_page_content($url) function calculate_tags(array $keywordsToTags, array $searchContents): array { - // Pondérations par contexte + // Context weights $contextWeights = [ 'title' => 3, 'url' => 3, @@ -131,7 +131,7 @@ function calculate_tags(array $keywordsToTags, array $searchContents): array if (!isset($tagScores[$tag])) { $tagScores[$tag] = 0; } - // Ajouter le poids selon le contexte + // Add weight based on context $tagScores[$tag] += $contextWeights[$context]; } } @@ -144,15 +144,15 @@ function calculate_tags(array $keywordsToTags, array $searchContents): array function filter_and_limit_tags(array $tagScores, int $minScore = 2, int $maxTags = 7): array { - // Filtrer les tags avec un score supérieur ou égal au minimum requis + // Filter tags with a score greater than or equal to the minimum required $filteredTags = array_filter($tagScores, function ($score) use ($minScore) { return $score >= $minScore; }); - // Trier les tags par score décroissant + // Sort tags by descending score arsort($filteredTags); - // Limiter le nombre de tags au maximum autorisé + // Limit the number of tags to the maximum allowed return array_slice(array_keys($filteredTags), 0, $maxTags); } @@ -169,13 +169,13 @@ function apply_auto_tags(array $data, ConfigManager $conf): array 'content' => $pageContent ]; - // Calcul des scores pour chaque tag + // Calculate scores for each tag $tagScores = calculate_tags($keywordsToTags, $searchContents); - // Filtrer et limiter les tags + // Filter and limit tags $tagsToAdd = filter_and_limit_tags($tagScores); - $tagsToAdd[] = 'auto-tagged'; // Ajouter un tag fixe + $tagsToAdd[] = 'auto-tagged'; // Added a fixed tag $existingTags = explode(' ', $data['link']['tags']); $data['link']['tags'] = implode(' ', array_unique(array_merge($existingTags, $tagsToAdd))); @@ -185,7 +185,7 @@ function apply_auto_tags(array $data, ConfigManager $conf): array function hook_auto_tag_plugin_render_editlink(array $data, ConfigManager $conf): array { if (!$data['link_is_new']) { - //return $data; // Ne pas réappliquer pour les liens non nouveaux + //return $data; // Do not reapply for non-new links } return apply_auto_tags($data, $conf);