Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,52 @@ import { MappingService } from "$lib/services/mappingService";
import { CapecService } from "$lib/services/capecService";

export const load = (({ params }) => {
const edition = params?.edition;
const version = edition == 'webapp' ? '2.2' : edition == 'mobileapp' ? '1.1' : '1.0';
let asvsVersion: string = "4.0.3";
if (params.version === '3.0') asvsVersion = '5.0';
if (!DeckService.hasEdition(edition)) error(
404, 'Edition not found. Only: ' + DeckService.getLatestEditions().join(', ') + ' are supported.');

// Load CAPEC data for webapp v3.0+
let capecData = undefined;
if (edition === 'webapp' && parseFloat(version) >= 3.0) {
capecData = CapecService.getCapecData(edition, version);
}

return {
edition: edition,
version: version,
versions: DeckService.getVersions(edition),
lang: 'en',
card: legacyCardCodeFix(params.card.toUpperCase()),
cards: new DeckService().getCardDataForEditionVersionLang(edition, version, 'en'),
routes: new Map<string, Route[]>([
['ASVSRoutes', FileSystemHelper.ASVSRouteMap(asvsVersion)]
]),
mappingData: (new MappingService()).getCardMappingForLatestEdtions(),
languages: DeckService.getLanguages(edition),
capecData
};

// Some QR code errors where done on the first printed decks. This will compensate for that.
function legacyCardCodeFix(card: string) {
return card.replace('COM', 'CM')
.replace('CO', 'C')
.replace('DVE', 'VE')
.replace('AC', 'AT');
}

}) satisfies PageServerLoad;

const edition = params.edition;

if (!DeckService.hasEdition(edition)) {
error(
404,
'Edition not found. Only: ' +
DeckService.getLatestEditions().join(', ') +
' are supported.'
);
}

const version = DeckService.getLatestVersion(edition);

let asvsVersion: string = "4.0.3";
if (params.version === '3.0') {
asvsVersion = '5.0';
}

let capecData;

if (edition === 'webapp' && parseFloat(version) >= 3.0) {
capecData = CapecService.getCapecData(edition, version);
}

return {
edition,
version,
versions: DeckService.getVersions(edition),
lang: 'en',
card: legacyCardCodeFix(params.card.toUpperCase()),
cards: new DeckService().getCardDataForEditionVersionLang(edition, version, 'en'),
routes: new Map<string, Route[]>([
['ASVSRoutes', FileSystemHelper.ASVSRouteMap(asvsVersion)]
]),
mappingData: new MappingService().getCardMappingForLatestEdtions(),
languages: DeckService.getLanguages(edition),
capecData
};

function legacyCardCodeFix(card: string) {
return card
.replace('COM', 'CM')
.replace('CO', 'C')
.replace('DVE', 'VE')
.replace('AC', 'AT');
}

}) satisfies PageServerLoad;
30 changes: 25 additions & 5 deletions scripts/check_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,31 @@ def main() -> None:
sys.exit(1)

# Run checker
checker = TranslationChecker(source_dir,
excluded_tags=["T02330", "T02530",
"T03130", "T03150", "T03170", "T03190", "T03240", "T03260",
"T03350", "T03420", "T03470", "T03490", "T03540", "T03580",
"T03710", "T03730", "T03750", "T03770", "T03772", "T03774"])
checker = TranslationChecker(
source_dir,
excluded_tags=[
"T02330",
"T02530",
"T03130",
"T03150",
"T03170",
"T03190",
"T03240",
"T03260",
"T03350",
"T03420",
"T03470",
"T03490",
"T03540",
"T03580",
"T03710",
"T03730",
"T03750",
"T03770",
"T03772",
"T03774",
],
)
results = checker.check_translations()

# Generate report
Expand Down
9 changes: 7 additions & 2 deletions scripts/check_translations_itest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def test_no_duplicate_tags_in_english(self) -> None:
duplicates.append(tag_id)
seen_ids.add(tag_id)

self.assertEqual(len(duplicates), 0, f"Duplicate tags found in {eng_file.name}: {duplicates}")
self.assertEqual(
len(duplicates),
0,
f"Duplicate tags found in {eng_file.name}: {duplicates}",
)

def test_tag_format(self) -> None:
"""Test that tags follow the T0xxxx format."""
Expand All @@ -95,7 +99,8 @@ def test_tag_format(self) -> None:

for tag_id in tags.keys():
self.assertIsNotNone(
tag_pattern.match(tag_id), f"Tag {tag_id} in {eng_file.name} doesn't match format T0xxxx"
tag_pattern.match(tag_id),
f"Tag {tag_id} in {eng_file.name} doesn't match format T0xxxx",
)

def test_generate_markdown_report(self) -> None:
Expand Down
63 changes: 52 additions & 11 deletions scripts/check_translations_utest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ def test_whitespace_only_detected_as_empty(self) -> None:

result = self.checker._check_translation_tags(english_tags, trans_tags)

self.assertIn("T00002", result["empty"], "Whitespace-only translation should be detected as empty")
self.assertIn(
"T00002",
result["empty"],
"Whitespace-only translation should be detected as empty",
)

def test_tabs_and_newlines_detected_as_empty(self) -> None:
english_tags = {"T00001": "Submit", "T00002": "Cancel"}
Expand All @@ -147,11 +151,18 @@ def test_extra_spaces_detected_as_untranslated(self) -> None:

result = self.checker._check_translation_tags(english_tags, trans_tags)

self.assertIn("T00001", result["untranslated"], "Extra spaces should be detected as untranslated")
self.assertIn(
"T00001",
result["untranslated"],
"Extra spaces should be detected as untranslated",
)

def test_properly_translated_no_issues(self) -> None:
english_tags = {"T00001": "Login", "T00002": "Register"}
trans_tags = {"T00001": "Iniciar Sesión", "T00002": "Registrar"} # Proper translations
trans_tags = {
"T00001": "Iniciar Sesión",
"T00002": "Registrar",
} # Proper translations

result = self.checker._check_translation_tags(english_tags, trans_tags)

Expand All @@ -176,9 +187,21 @@ def test_compound_locale_files_included_in_file_groups(self) -> None:

self.assertIn("test-cards-1.0", file_groups)
files = [f.name for f in file_groups["test-cards-1.0"]]
self.assertIn("test-cards-1.0-no_nb.yaml", files, "Norwegian (no_nb) file should be included")
self.assertIn("test-cards-1.0-pt_br.yaml", files, "Portuguese Brazil (pt_br) file should be included")
self.assertIn("test-cards-1.0-pt_pt.yaml", files, "Portuguese Portugal (pt_pt) file should be included")
self.assertIn(
"test-cards-1.0-no_nb.yaml",
files,
"Norwegian (no_nb) file should be included",
)
self.assertIn(
"test-cards-1.0-pt_br.yaml",
files,
"Portuguese Brazil (pt_br) file should be included",
)
self.assertIn(
"test-cards-1.0-pt_pt.yaml",
files,
"Portuguese Portugal (pt_pt) file should be included",
)

def test_compound_locale_not_excluded_by_old_len_filter(self) -> None:
"""Regression test: ensure 5-char locale codes are NOT filtered out."""
Expand All @@ -203,7 +226,11 @@ def test_norwegian_translation_issues_detected(self) -> None:
results = self.checker.check_translations()

self.assertIn("test-cards-1.0", results)
self.assertIn("no_nb", results["test-cards-1.0"], "Norwegian (no_nb) results should be present")
self.assertIn(
"no_nb",
results["test-cards-1.0"],
"Norwegian (no_nb) results should be present",
)
no_nb_issues = results["test-cards-1.0"]["no_nb"]
self.assertIn("T00004", no_nb_issues["missing"], "T00004 should be missing in no_nb")
self.assertIn("T00003", no_nb_issues["empty"], "T00003 should be empty in no_nb")
Expand All @@ -213,9 +240,17 @@ def test_portuguese_brazil_untranslated_detected(self) -> None:
results = self.checker.check_translations()

self.assertIn("test-cards-1.0", results)
self.assertIn("pt_br", results["test-cards-1.0"], "Portuguese Brazil (pt_br) results should be present")
self.assertIn(
"pt_br",
results["test-cards-1.0"],
"Portuguese Brazil (pt_br) results should be present",
)
pt_br_issues = results["test-cards-1.0"]["pt_br"]
self.assertIn("T00002", pt_br_issues["untranslated"], "T00002 should be untranslated in pt_br")
self.assertIn(
"T00002",
pt_br_issues["untranslated"],
"T00002 should be untranslated in pt_br",
)

def test_portuguese_portugal_fully_translated_no_issues(self) -> None:
"""Test that a fully-translated Portuguese Portugal (pt_pt) file produces no issues."""
Expand All @@ -230,7 +265,11 @@ def test_lang_names_in_report(self) -> None:
report = self.checker.generate_markdown_report()

self.assertIn("Norwegian", report, "Norwegian display name should appear for no_nb")
self.assertIn("Portuguese (Brazil)", report, "Portuguese (Brazil) display name should appear for pt_br")
self.assertIn(
"Portuguese (Brazil)",
report,
"Portuguese (Brazil) display name should appear for pt_br",
)


class TestCoverageBranches(unittest.TestCase):
Expand Down Expand Up @@ -262,7 +301,9 @@ def test_get_file_groups_skips_archive_files(self) -> None:
file_groups = checker.get_file_groups()
all_files = [f.name for files in file_groups.values() for f in files]
self.assertNotIn(
"webapp-archive-cards-1.0-en.yaml", all_files, "Files with 'archive' in name should be skipped"
"webapp-archive-cards-1.0-en.yaml",
all_files,
"Files with 'archive' in name should be skipped",
)

def test_check_translations_no_english_file(self) -> None:
Expand Down
Loading
Loading