Skip to content

[v4] how to generate catalogs from external source #1614

Discussion options

You must be logged in to vote
import PO from "pofile"
import { CatalogFormatter, CatalogType, MessageType } from "@lingui/conf"

type POItem = InstanceType<typeof PO.Item>

const splitOrigin = (origin: string) => {
  const [file, line] = origin.split(":")
  return [file, line ? Number(line) : null] as [file: string, line: number]
}

function deserialize(items: POItem[]): CatalogType {
  return items.reduce<CatalogType<POCatalogExtra>>((catalog, item) => {
    const message: MessageType<POCatalogExtra> = {
      translation: item.msgstr[0],
      comments: item.extractedComments || [],
      context: item.msgctxt ?? null,
      obsolete: item.flags.obsolete || item.obsolete,
      origin: (item.references || []).map((ref)

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@batusai513
Comment options

Comment options

You must be logged in to vote
4 replies
@batusai513
Comment options

@timofei-iatsenko
Comment options

@timofei-iatsenko
Comment options

Answer selected by batusai513
@batusai513
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants