Skip to content

Keep Your UI Copy in One Place

Naseebullah AhmadiSenior Software Engineer, London

All of the site's copy moves out of components into one central file, and components read it through `t('key')`. The keys are typed against that file, so they autocomplete, and a typo or a deleted line fails the type-check instead of shipping blank.

4 min read
#frontend

Copy written inline drifts: the same label gets worded three ways, and changing a sentence starts with a grep. Put all copy in one object instead, grouped by the component that shows it, and read it through a small t bound to that group. #typescript turns the object's shape into the set of valid keys, so t('sayHi') autocompletes and t('sayHello') doesn't compile.

@itsnas footer.tsx
codefooter.tsx
// @src/code/copy
const t = copy('Footer')
 
export function Footer({ year }: { year: number }) {
  return (
    <footer>
      <a href="/contact">{t('sayHi')}</a>
      <p>{t('copyright', { year })}</p>
    </footer>
  )
}
main
Nas (@itsnas)