Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing for po files? #5

Open
N8Brooks opened this issue Apr 6, 2023 · 0 comments
Open

Typing for po files? #5

N8Brooks opened this issue Apr 6, 2023 · 0 comments

Comments

@N8Brooks
Copy link

N8Brooks commented Apr 6, 2023

When using the preact-cli, importing po files directly gives me ts and webpack errors.

TS:

typescript: Cannot find module 'src/assets/locales/en.po' or its corresponding type declarations.

npm run build (comes with preact-cli)

[...]
X ERROR ./src/locales/en.ts
ERROR in ./src/locales/en.ts(3,22):
TS2307: Cannot find module 'src/assets/locales/en.po' or its corresponding type declarations.

This is using a locales/en.ts based on the examples with its associated po file in assets/locales/en.po.

import messages from "src/assets/locales/en.po";
import { createLocale } from "preact-localized";

export default createLocale(messages);

When adding some ignore comments, everything works!

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

import messages from "src/assets/locales/en.po";
import { createLocale } from "preact-localized";

export default createLocale(messages);

Here is the preact.config.js that I am using (it may be handy to add an example for this - I'll open a PR if you're interested).

import CopyWebpackPlugin from 'copy-webpack-plugin';
import { resolve } from "path";

export default (config) => {
  config.plugins.push(
    new CopyWebpackPlugin({
      patterns: [{
        from: "*",
        to: "src/assets/locales",
        context: resolve(__dirname, "src/assets/locales")
      }]
    })
  );

  config.module.rules.push({
    test: /\.po$/,
    use: "react-localized-loader",
  });
};

Is there a better way to include the definitions for po files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant