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

Feature: lingui extract should collect messages from multiple sources #257

Closed
HamidAghdaee opened this issue Aug 8, 2018 · 11 comments
Closed

Comments

@HamidAghdaee
Copy link

Thank you so much for this wonderful library.

One issue we're facing at the moment::

Our application is large enough that we want to extract translations from various src folders in our application into different locale folders. Currently there is no way to pass certain config options to lingui extract command such as srcPathDirs and <rootDir>/locale

It would be nice to either be able to pass these in as parameters or to force the command to read these from a custom config file.

Thanks again.

@tricoder42
Copy link
Contributor

Hey @HamidAghdaee,
I was facing similar issue some time ago but was lazy enough to find a temporary workaround :D I'm working on CLI atm, so let's focus on this.

Just to clarify: you have N source folders and you would like to extract message to N separate locale folders, right?

Something like:

{
   "localeDirs": {
      "./locale/package1": "./src/package1",
      "./locale/package2": "./src/package2",
    }
}

@HamidAghdaee
Copy link
Author

@tricoder42 yes. that would solve part of our problem. Our use case is more like what you're trying to solve here: #14

We maintain our code in packages in a mono-repo of npm published packages, manages by yarn workspaces and Lerna.

We want each package to maintain their own local locale files. For one of the packages there are enough translations that having more than one locale folder is a necessity. For the others one locale folder is sufficient, but I don't want to install lingui for each package. I want to run lingui extract as part of a lerna exec command, which should pass the local config file to the package to the lingui command.

Let me know what you think.

Thanks.

@tricoder42
Copy link
Contributor

Make sense. It should be enough to have @lingui/cli installed in the root of monorepo and then running lingui add-locale|extract|compile in root would execute the command in each workspace.

That's what I was suggesting with

{
   "localeDirs": {
      "./locale/package1": "./src/package1",
      "./locale/package2": "./src/package2",
    }
}

but we could pick this config from workspaces config.

Regarding namespaces: This might be indeed related, but namespaces are mostly about having a single locale folder which collects messages from several other sources (1:N mapping). For example you might have packages App, CreditCardInput, RelativeDateTime and messages from all of them will be collected in the same locale directory, but msgIds from CreditCardInput will be namespaced with @CreditCardInput/ and so on:

{
   "msg.header": "Header from App", 
   "@CreditCardInput/msg.header": "Header from CreditCardInput",
   "@RelativeDateTime/msg.header": "Header from RelativeDateTime",
}

@HamidAghdaee
Copy link
Author

@tricoder42 with regards to your first point:

I just don't to have to add a row for each package to the config you mentioned. lerna exec already executes any command for every package. And I want to direct it to use the config file local to the package for which it is executing.

I agree with your point about name-spacing. That could be helpful for us. One challenge I see however is:

  1. If the messageId is extracted to be the same as message value, then how do you namespace it? Would there be a namespacing not based on the key, but something else? I'm talking about the case where the developer doesn't provide an explicit id.

thanks.

@tricoder42
Copy link
Contributor

I just don't to have to add a row for each package to the config you mentioned. lerna exec already executes any command for every package. And I want to direct it to use the config file local to the package for which it is executing.

I understand that.

There' one possible workaround which should work out of the box: Add lingui config to each package:

{
  "lingui": {
    "localeDir": "./locale"
  }
}

The problem is that if you have any additional config in root, it will be overwritten. On the other hand, this should create locale dir inside each package with such config.

Namespacing is still in progress and there're many challenges to solve. But yes, if developer doen't provide explicit ID, then the ID is the message itself. Instead of @namespace/msg.id it would be @namespace/Message string. There's no difference. The messageID isn't visible for user anyway, so it could be anything.

@HamidAghdaee
Copy link
Author

I see. You're right about the packages within the monorepo solution you mentioned. I forgot that lerna exec makes the cwd the package in which it's executing. Having multiple src and locale combos in the same config is still useful for us for the case of splitting translations in the same package.

With regards to name-spacing:

How do you intend to determine what the namespace is to be if not specified in the key by the user? That's what i18next does and I have to say I don't love it.

On a related note, it would be nice to be able to do some mapping of keys when the keys are generated messageIds. After all, for the English (in our case our default lanaguage) you end up with this in your en.json file:

{
"long message....": "long message"
}

It would be nice to make it so that a mapping function can be applied generate keys from the value (or other factors such as file name, etc) to shorten the key string.

@tricoder42
Copy link
Contributor

I haven't really thought about all edge cases of namespacing. I'm working on #179, adding support for .po and possibly .xliff files. Also I'm preparing a video tutorial, so there's too many things going on in my head and I need to release 3.0 anyway before namespaces :) If you have any good points or suggestions, feel free to share it in #14, but right now I'll I can give you is my idea of solution, which is far from the final solution :)

@tricoder42 tricoder42 changed the title no way to pass certain config options to lingui extract command Feature: lingui extract should collect messages from multiple sources Aug 9, 2018
@tricoder42 tricoder42 added this to the 3.0 Macros milestone Aug 10, 2018
@tricoder42
Copy link
Contributor

tricoder42 commented Aug 25, 2018

Here's a draft of splitting source catalogs. Any comments welcome.

@tricoder42 tricoder42 self-assigned this Aug 26, 2018
@tricoder42 tricoder42 removed this from the 3.0 Macros milestone Aug 26, 2018
@HamidAghdaee
Copy link
Author

@tricoder42 I think the draft would address our needs. What do you think the estimate for this being available would be?

In the meantime, can you think of any workarounds for this at the moment? My primary need is to have multiple catalogs located in different folders within the same npm package?

It seems like at the moment js-lingui only understands one catalog per package. If I put other json files (Even locale/en/messages.json file) anywhere in the repo, it only reads the json file from the locale folder specified in the root jslingui config.

Thanks for your help.

@tricoder42
Copy link
Contributor

I'm planning to work & release it next weekend. It's been on a paper for too long.

At the moment there's no way to have more than one message catalog, unfortunately.

@tricoder42
Copy link
Contributor

New catalogs were already merged to next branch and will be released in next major release, LinguiJS v3.0. See #334 how to test pre-release.

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

No branches or pull requests

2 participants