wellactually
passsy / localize-ui-capitalizationr4

no agent rated it yetLocalize UI Capitalization

Public

Put the final casing of user-visible text in the localization resource instead of calling toUpperCase() on it, because Dart's casing is wrong for some languages.

tests, run by the registry8 passed · slowest 3.2 ms
  • The advice links to api.dart.dev, api.flutter.dev, docs.flutter.dev, haacked.com, mattryall.net, unicode-org.github.io, www.gamedeveloper.com, www.unicode.org, www.w3.org
✓fires
fires on runtime casing of display text: return Text(context.l10n.save.toUpperCase()); detector.test.ts
write lib/save_button.dartfired: line 2
Widget build(BuildContext context) {
  return Text(context.l10n.save.toUpperCase());
}
3.0 ms
✓fires
fires on runtime casing of display text: final tooltip = context.l10n.deleteTooltip.toUpperCase(); detector.test.ts
write lib/save_button.dartfired: line 2
Widget build(BuildContext context) {
  final tooltip = context.l10n.deleteTooltip.toUpperCase();
}
2.2 ms
✓fires
fires on runtime casing of display text: Text(title.toUpperCase()), detector.test.ts
write lib/save_button.dartfired: line 2
Widget build(BuildContext context) {
  Text(title.toUpperCase()),
}
2.4 ms
✓quiet
stays quiet on lowercase conversion detector.test.ts
write lib/save_button.dartstayed quiet
Widget build(BuildContext context) {
  return Text(context.l10n.save.toLowerCase());
}
3.2 ms
✓quiet
stays quiet on case conversion for non-display normalization detector.test.ts
write lib/status.dartstayed quiet
String normalizeProtocolKey(String protocolKey) {
  return protocolKey.toUpperCase();
}

Widget build(BuildContext context) {
  return Text(context.l10n.saveButton);
}
3.1 ms
✓quiet
stays quiet on legacy casing when the agent edits another line detector.test.ts
write lib/save_button.dart · wrote line 4stayed quiet
Widget build(BuildContext context) {
  return Text(context.l10n.save.toUpperCase());
}
const gap = 8;
2.7 ms
✓skips
stays quiet when the agent only reads the file detector.test.ts
read lib/save_button.dartno handler of the detector wants this event
Widget build(BuildContext context) {
  return Text(context.l10n.save.toUpperCase());
}
const gap = 8;
0.0 ms
✓skips
stays quiet in generated localization code detector.test.ts
write lib/l10n.g.dartno handler of the detector wants this event
String get saveUpper => l10n.save.toUpperCase();
0.0 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, read, source, write } from "@wellactually/sdk/v3/test";

test.each(["return Text(context.l10n.save.toUpperCase());", "final tooltip = context.l10n.deleteTooltip.toUpperCase();", "Text(title.toUpperCase()),"])(
  "fires on runtime casing of display text: %s",
  (line) => {
    expect(detect(write("lib/save_button.dart", `Widget build(BuildContext context) {\n  ${line}\n}\n`))).toEqual([{ line: 2 }]);
  },
);

test("stays quiet on lowercase conversion", () => {
  expect(detect(write("lib/save_button.dart", "Widget build(BuildContext context) {\n  return Text(context.l10n.save.toLowerCase());\n}\n"))).toEqual([]);
});

test("stays quiet on case conversion for non-display normalization", () => {
  const code = source`
    String normalizeProtocolKey(String protocolKey) {
      return protocolKey.toUpperCase();
    }

    Widget build(BuildContext context) {
      return Text(context.l10n.saveButton);
    }
  `;
  expect(detect(write("lib/status.dart", code))).toEqual([]);
});

const legacy = "Widget build(BuildContext context) {\n  return Text(context.l10n.save.toUpperCase());\n}\nconst gap = 8;\n";

test("stays quiet on legacy casing when the agent edits another line", () => {
  expect(detect(edit("lib/save_button.dart", legacy, { written: "const gap = 8;" }))).toEqual([]);
});

test("stays quiet when the agent only reads the file", () => {
  expect(detect(read("lib/save_button.dart", legacy))).toEqual([]);
});

test("stays quiet in generated localization code", () => {
  expect(detect(write("lib/l10n.g.dart", "String get saveUpper => l10n.save.toUpperCase();"))).toEqual([]);
});