stringsListHandler function
GET /api/strings?locale=<loc> — every source key with the matching
translation entry. Returns 400 if the locale is missing or unknown
to the project (i.e. not in target_locales and not the source
locale).
Implementation
Response stringsListHandler(DialectProject project, Request req) {
final locale = req.url.queryParameters['locale'];
if (locale == null || locale.isEmpty) {
return _jsonError(400, 'Missing `locale` query parameter.');
}
final isSource = locale == project.config.sourceLocale;
final isTarget = project.config.targetLocales.contains(locale);
if (!isSource && !isTarget) {
return _jsonError(
404,
'Locale `$locale` is not configured (source: '
'`${project.config.sourceLocale}`, '
'targets: ${project.config.targetLocales}).',
);
}
return Response.ok(
jsonEncode(stringsJson(project, locale)),
headers: const {'content-type': 'application/json; charset=utf-8'},
);
}