Skip to content

Commit 0e4b08d

Browse files
authored
docs(readme): Add links to line numbers for locales (DenverCoder1#368)
1 parent a95ae9c commit 0e4b08d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/translation-progress.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function getProgress(array $translations): array
1919
"Present",
2020
];
2121

22+
$translations_file = file(__DIR__ . "/../src/translations.php");
2223
$progress = [];
2324
foreach ($translations as $locale => $phrases) {
2425
$translated = 0;
@@ -29,10 +30,12 @@ function getProgress(array $translations): array
2930
}
3031
$percentage = round(($translated / count($phrases_to_translate)) * 100);
3132
$locale_name = Locale::getDisplayName($locale, $locale);
33+
$line_number = getLineNumber($translations_file, $locale);
3234
$progress[$locale] = [
3335
"locale" => $locale,
3436
"locale_name" => $locale_name,
3537
"percentage" => $percentage,
38+
"line_number" => $line_number,
3639
];
3740
}
3841
// sort by percentage
@@ -42,6 +45,18 @@ function getProgress(array $translations): array
4245
return $progress;
4346
}
4447

48+
/**
49+
* Get the line number of the locale in the translations file
50+
*
51+
* @param array $translations_file The translations file
52+
* @param string $locale The locale
53+
* @return int The line number of the locale in the translations file
54+
*/
55+
function getLineNumber(array $translations_file, string $locale): int
56+
{
57+
return key(preg_grep("/^\\s*\"$locale\"\\s*=>\\s*\\[/", $translations_file)) + 1;
58+
}
59+
4560
/**
4661
* Convert progress to labeled badges
4762
*
@@ -55,7 +70,8 @@ function progressToBadges(array $progress): string
5570
$badges .= str_repeat("| --- ", $per_row) . "|" . "\n";
5671
$i = 0;
5772
foreach (array_values($progress) as $data) {
58-
$badges .= "| `{$data["locale"]}` - {$data["locale_name"]} <br /> ![{$data["locale_name"]} {$data["percentage"]}%](https://progress-bar.dev/{$data["percentage"]}) ";
73+
$line_url = "https://github.com/DenverCoder1/github-readme-streak-stats/blob/main/src/translations.php#L{$data["line_number"]}";
74+
$badges .= "| [`{$data["locale"]}`]({$line_url}) - {$data["locale_name"]} <br /> [![{$data["locale_name"]} {$data["percentage"]}%](https://progress-bar.dev/{$data["percentage"]})]({$line_url}) ";
5975
$i++;
6076
if ($i % $per_row === 0) {
6177
$badges .= "|\n";

0 commit comments

Comments
 (0)