-
Notifications
You must be signed in to change notification settings - Fork 378
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
Cannot extract using i18n.plural : undefined is not iterable! #1022
Comments
Hey mate, i could take a look to the issue. But... what do you think if you give some days and i migrate your entire codebase to Lingui v3 with the best practices? |
HI @semoal , I am delighted of your proposition and of course, I can only accept if that solves our problem. I tried to migrate the whole today but the step were not straightforward so I rolled back. You can fork and create a repo, I'll reproduce the PR when needed. |
I took a look and looks there's no much to change and I'm sure that for the future will be easier for you, with all the power of Lingui with plurals, select and other cool methods. (Of course will be a good real example how a migration to v3 can be done and useful for documenting or fixing any that is wrong on v3) I'll create a fork this weekend and probably in a few days I'll create a pr! 👍🏻 |
Along today or tomorrow I'll create the pull request mate, I'm polishing some details :) I'm already green our your entire suite =) Test Suites: 222 passed, 222 total
Tests: 4 skipped, 1271 passed, 1275 total
Snapshots: 88 passed, 88 total
Time: 75.51s
Ran all test suites.
✨ Done in 76.80s. |
Thanks @semoal that's great, did you manage to use |
Yes, just tried to use the macro and the plural() macro and both works nicely :) .tsx file somehwere there: <Plural value={0} one="# prueba" other="# pruebas" />
{plural(0, {
one: '# message',
other: '# messages',
})} .po extracted:
|
Here is the pull request @kopax pass-culture/pass-culture-app-native#842 |
@semoal, I just rebased and tested your PR: and it seems the syntax in import { i18n } from '@lingui/core'
import { fr } from 'make-plural/plurals'
i18n.loadLocaleData({
fr: { plurals: fr },
})
export const activate = async (locale: string) => {
const { messages } = await import(`../locales/${locale}/messages`)
i18n.load(locale, messages)
i18n.activate(locale)
} Result on startup error:
Do you have a clue? I am now investigating. |
Yes, that's my bad (not an expert react-native developer, just web ^^) looks metro/native/expo i don't know how it's called doesn't support dynamic imports you can reimplement this to: export async function activate(locale: string) {
let catalog: {messages: Messages}
switch (locale) {
case 'en':
catalog = await import('./locales/en/messages.po')
break
case 'fr':
default:
catalog = await import('./locales/fr/messages.po')
break;
}
i18n.load(locale, catalog.messages)
i18n.activate(locale)
} Feel free to ping me if you need anything else by my side, Lingui questions or whenever you need =) |
@semoal thanks again for your support, so far, I have removed the import the dynamic import part and there's an issue with
I've checked and followed the recommendation to clean the projet, despite the module is existing in |
eemeli/make-plural#15 |
Actually loading the plurals is required, so the loadLocaleData is mandatory :/ |
Yes, I just succeded to load the plural editing my /**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
module.exports = {
+ resolver: {
+ sourceExts: ['js', 'ts', 'tsx', 'mjs'],
+ },
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
maxWorkers: 2,
} I still have the error from the screenshot. That's how my import { i18n, Messages } from '@lingui/core'
import { fr } from 'make-plural/plurals'
i18n.loadLocaleData({
fr: { plurals: fr },
})
export async function activate(locale: string) {
let catalog: { messages: Messages }
switch (locale) {
case 'fr':
default:
catalog = await import('locales/fr/messages')
break
}
i18n.load(locale, catalog.messages)
i18n.activate(locale)
} Edit Interesting, in my code, if I replace: - text={t`dans l’année de tes 18 ans, obtiens l’aide financière pass Culture d’un montant de ${deposit} à dépenser dans l’application.`}
+ text={t`dans l’année de tes 18 ans, obtiens l’aide financière pass Culture d’un montant de à dépenser dans l’application.`} It seems to be an issue with template literals. |
I figured the cause, it seems that now undefined cannot be |
Let me hotfix this 👍🏻 , try to patch the package and check if we need to change anything else: var result = formatMessage(translation);
return result && result.trim(); Already created the pr: #1030 , I'll fix anything you find and i'll release a new version in the same moment :) |
This seems to work: Why is |
Result shouldn't be a function because are the messages interpolated, I'm checking if i can reproduce the issue in our test suite |
I still see a lot of unicode chars displayed, I have tried to remove them, using some HTML code. Can you tell me how for example I can replace |
Just an empty space should be enough if not, you can use perfectly the equivalent in html code entities |
I've tried both and none of them work. Why would you strip the characters ? Perhaps you can add an option to toggle the feature for such cases? |
I can't remember now why Tomas took that direction, we had issues with some bundlers and we decided to keep it like just html entities.
In this case is recommended to use it like this:
offtopic could you try to typeof the previous issue to check if everything works good?:
|
We use syntax literal so it's a template literal that caused to be a
I've updated the
We use a lot of unicode characteres to add unbreakable spaces, etc... Can this feature be restored? Otherwise, how do you recommend to solve it? |
Let me review the unicode topic |
Give me tonight to analyse how can we solve the unicode part and tomorrow we conclude this ;) |
Alright, thanks again for helping us in the migration process ! Good luck, |
It's all merged. I'll close it for now and re-open it if needed. Thanks again for helping us migrating the library, that's really cool. |
We have another issue here: Despite
The text is not displayed: The following code: text={
t`dans l’année de tes 18 ans, obtiens l’aide financière pass Culture d’un montant de\u00a0` +
deposit +
`\u00a0à dépenser dans l’application.`
} cause the following: Adding log in the component that receive the text:
It seems that the macro is having issue when using string interpolation. |
This fix the error :
I am now concerned of the risk to have a bunch of error like this unspotted. |
I've tried to replicate the issue on the example/create-react-app application which uses create-reac-app under the hood and couldn't reproduce it. |
I don't think you can, as explained in our How about bootstrapping a fresh react native application for running such test?
Considering the role of lingui, I have doubt about it, the JS engine should be working the same as in the browser. The one difference is what will be rendered in the DOM, lingui should return strings, strings should be in |
Yes, i'm going to bootstrap a react native application. Give it a try if you can to reproduce it in a create-react-app example, update lingui to latest (make sure installed is 3.8.4) and tell me if you can reproduce it |
Yes, that's unfortunate, I am already on it. |
Thanks, I was still working on my boilerplate, so I am giving up. I will try to see if there's a way to start the application without those keys to see if we can investigate further. |
We could talk on a meeting if getting these keys are so risky for an external developer, I'm open to anything, just want to help :) |
Perhaps a peer programming session over meet can help solve this? |
I'm sure that worst can't go =) today i'm busy at work, so if you want to try to reproduce and if not we speak tomorrow? |
If you can't reproduce it I have doubt on how to reproduce it myself with a fresh native project. I've checked with our team and starting the app without those secrets is not possible. I am almost sure I can help you investigate if you want to dig to the root cause through a peer programming session, let me know if you want to schedule that tomorrow. So far, I warned the dev team that v3 now bring issue with unicode chars and string literals. so far we have found alternatives for every dubious case we got, the worst alternative was to call a |
Yes, let's schedule tomorrow. I have already picked 9:30 and 14:00, i'm free all the afternon |
OK, I've just scheduled on meet a 1h slot between 2pm and 3pm, you have the right to update the time, I am also free for the call the whole afternoon, looking forward with thanks ! |
We got another issue which is blocking for us. After releasing our application in app center with a real android build, it seems that the unicode chars are not replaced in every place, for exemple: 2nd thing is that the bug with the text on
I think we may have to revert to v2 especially because of 2, we'll see tomorrow. This is what we got in
|
Hi @semoal , I've just tested a production build with lingui 3.8.6 and I still have unicode issue in production, now
And view is still showing invalid chars: We also have issue rendering our text at some place and this breaks our errors message, probably because the object returned is a function not a string: |
Quick update: One thing we can't fix without breaking others users, it's not stripping spaces at the end of strings. Not inmediately fixFor example this case: <Text>{t`EAN\u00a0`}</Text> Should be like this if you want that space, or <Text>{t`EAN`}{\u00a0}</Text>
Inmediately fix
Pending for your side confirmation
Pending for my side
|
Our v3 FixThis allow us to not revert to v2 since we have no more visual regression: https://github.com/pass-culture/pass-culture-app-native/pull/864/files Unicode fixThis is how we solve the unicode issue, but now our Development variable interpolation broken
We still have the issue in development and I can't understand what can cause the behavior I showed you during the PP. It's not just a warning, the whole sentence doesn't get displayed and that's pretty bad while developing UI. I hope this to be fixed, since this is not blocking our v3 migration, I can offer to do another peer programming session anytime if you need to have the environment. Unicode trim fix
I am much interested in that feature, can you also please confirm that unicode does not work only if they are around the sentence? Because we have:
And this seems to render correctly both in development and production Unit tests
Since the upgrade to v3, our unit test doesn't exit properly anymore. It hang and catch later the success signal, do you know why? |
Hello @semoal , I'd like to know if action will be taken regarding the issue we have with string, we still find a lot of view displayed like follow after migration to v3: Also, our test execution time has increased from 4 to 8 min because of :
This started after merging the v3 migration: pass-culture/pass-culture-app-native#845 Do you have a clue why the test are improperly configured with lingui v3 ? |
I've created two separate issues and suggest that we close that one so newcomers can get the proper feed and have this one linked. |
Hello, we use lingui v2.9.2 and we got issue extracting using
i18n.plural
:This works:
This fail:
It fails when we run
lingui extract --clean
, with the following error:We rather use the synthax of
i18n.plural
instead ofi18n._
, how can this be fixed ?Reproduction
package.json
git clone https://github.com/pass-culture/pass-culture-app-native.git cd pass-culture-app-native nvm use yarn yarn run translations:extract
Related issues
The text was updated successfully, but these errors were encountered: