Skip to content

Commit a749c0b

Browse files
committed
fix(winget): remove hardcoded en-US locale from getVersionManifests
getLocale endpoints now read DefaultLocale from the version manifest and use getDefaultLocaleManifestPath to construct the correct locale file path, instead of relying on a hardcoded en-US assumption.
1 parent 945bc1c commit a749c0b

4 files changed

Lines changed: 55 additions & 38 deletions

File tree

server/routes/api/winget/packageManifests/[id].ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
buildPackageIndex,
99
fetchManifestContent,
1010
getVersionManifests,
11+
getDefaultLocaleManifestPath,
1112
createWinGetError,
1213
} from "../../../../utils/winget";
1314

@@ -116,13 +117,23 @@ export default defineHandler(async (event: H3Event) => {
116117
versionEntry.DefaultLocale = parsed.DefaultLocale;
117118
versionEntry.Channel = parsed.Channel;
118119
versionEntry.Manifest = parsed;
120+
121+
// Fetch locale manifest using DefaultLocale from version manifest
122+
if (parsed.DefaultLocale) {
123+
try {
124+
const localeContent = await fetchManifestContent(
125+
getDefaultLocaleManifestPath(packageId, version, parsed.DefaultLocale),
126+
);
127+
const localeParsed = parseYAML(localeContent) as Record<string, any>;
128+
if (!versionEntry.Locales) versionEntry.Locales = [];
129+
versionEntry.Locales.push(localeParsed);
130+
} catch {
131+
// locale file may not exist
132+
}
133+
}
119134
} else if (filename.match(/\.installer\.yaml$/)) {
120135
// Installer manifest
121136
versionEntry.Installers = parsed.Installers;
122-
} else if (filename.match(/\.locale\./)) {
123-
// Locale manifest
124-
if (!versionEntry.Locales) versionEntry.Locales = [];
125-
versionEntry.Locales.push(parsed);
126137
}
127138
}
128139

server/routes/api/winget/packages/[id]/versions/[version]/locales.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { defineHandler, getRouterParam } from "nitro/h3";
55
import type { LocaleMultipleResponse, LocaleSchema } from "../../../../../../../utils/winget";
66
import {
77
getVersionManifests,
8+
getDefaultLocaleManifestPath,
89
fetchManifestContent,
910
createWinGetError,
1011
} from "../../../../../../../utils/winget";
@@ -91,27 +92,36 @@ export default defineHandler(async (event) => {
9192
// Find all locale manifests
9293
const locales: LocaleSchema[] = [];
9394

94-
for (const manifestPath of manifestFiles) {
95-
const filename = manifestPath.split("/").pop()!;
95+
// Read version manifest to get DefaultLocale
96+
const versionManifestPath = manifestFiles.find(
97+
(path) => path.split("/").pop() === `${packageId}.yaml`,
98+
);
9699

97-
// Match locale files: {PackageId}.locale.{locale}.yaml
98-
const localeMatch = filename.match(/\.locale\.([^.]+)\.yaml$/);
100+
let defaultLocale = "en-US";
101+
if (versionManifestPath) {
102+
try {
103+
const content = await fetchManifestContent(versionManifestPath);
104+
const manifest = parseYAML(content) as Record<string, any>;
105+
if (manifest.DefaultLocale) {
106+
defaultLocale = manifest.DefaultLocale;
107+
}
108+
} catch {
109+
// keep fallback
110+
}
111+
}
99112

100-
if (localeMatch && localeMatch[1]) {
101-
const locale = localeMatch[1];
113+
const localePath = getDefaultLocaleManifestPath(packageId, version, defaultLocale);
102114

103-
try {
104-
const content = await fetchManifestContent(manifestPath);
105-
const manifest = parseYAML(content) as Record<string, any>;
115+
try {
116+
const content = await fetchManifestContent(localePath);
117+
const manifest = parseYAML(content) as Record<string, any>;
106118

107-
locales.push({
108-
PackageLocale: locale,
109-
...manifest,
110-
});
111-
} catch {
112-
locales.push({ PackageLocale: locale });
113-
}
114-
}
119+
locales.push({
120+
PackageLocale: defaultLocale,
121+
...manifest,
122+
});
123+
} catch {
124+
locales.push({ PackageLocale: defaultLocale });
115125
}
116126

117127
const response: LocaleMultipleResponse = {

server/routes/api/winget/packages/[id]/versions/[version]/locales/[locale].ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { defineHandler, getRouterParam } from "nitro/h3";
55
import type { LocaleSingleResponse, LocaleSchema } from "../../../../../../../../utils/winget";
66
import {
77
getVersionManifests,
8+
getDefaultLocaleManifestPath,
89
fetchManifestContent,
910
createWinGetError,
1011
} from "../../../../../../../../utils/winget";
@@ -95,17 +96,8 @@ export default defineHandler(async (event) => {
9596
return createWinGetError(event, 404, `Version ${version} of package '${packageId}' not found`);
9697
}
9798

98-
// Find the specific locale manifest
99-
const localeFilename = `${packageId}.locale.${locale}.yaml`;
100-
const localeManifestPath = manifestFiles.find((path) => path.split("/").pop() === localeFilename);
101-
102-
if (!localeManifestPath) {
103-
return createWinGetError(
104-
event,
105-
404,
106-
`Locale '${locale}' not found for version ${version} of package '${packageId}'`,
107-
);
108-
}
99+
// Construct locale manifest path directly
100+
const localeManifestPath = getDefaultLocaleManifestPath(packageId, version, locale);
109101

110102
try {
111103
const content = await fetchManifestContent(localeManifestPath);
@@ -119,6 +111,14 @@ export default defineHandler(async (event) => {
119111

120112
return response;
121113
} catch (error) {
122-
return createWinGetError(event, 500, `Failed to parse locale manifest: ${String(error)}`);
114+
const message = String(error);
115+
if (message.includes("404")) {
116+
return createWinGetError(
117+
event,
118+
404,
119+
`Locale '${locale}' not found for version ${version} of package '${packageId}'`,
120+
);
121+
}
122+
return createWinGetError(event, 500, `Failed to parse locale manifest: ${message}`);
123123
}
124124
});

server/utils/winget.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,7 @@ export function getVersionManifests(
402402

403403
const basePath = `manifests/${letter}/${publisher}/${name}/${version}`;
404404

405-
return [
406-
`${basePath}/${packageId}.yaml`,
407-
`${basePath}/${packageId}.installer.yaml`,
408-
`${basePath}/${packageId}.locale.en-US.yaml`,
409-
];
405+
return [`${basePath}/${packageId}.yaml`, `${basePath}/${packageId}.installer.yaml`];
410406
}
411407

412408
/**

0 commit comments

Comments
 (0)