Romanchuk / angular-i18next

angular v10+ integration with i18next v19.4+
MIT License
130 stars 33 forks source link

Update to last i18next version and Angular v-17 #114

Closed luca-peruzzo closed 1 year ago

luca-peruzzo commented 1 year ago

closes #113

JacobF7 commented 1 year ago

@Romanchuk - do you think we'll get this Merged anytime soon. It's currently blocking our upgrade to the latest Angular

MathiasWasAlreadyTaken commented 1 year ago

Looking at his recent activity on Github (last update in June), I would suggest we create a fork from this and use that instead. He might even been drafted to the war...

Romanchuk commented 1 year ago

@MathiasWasAlreadyTaken Do you think i can't merge it while in a frontline?

Romanchuk commented 1 year ago

Please try: https://www.npmjs.com/package/angular-i18next/v/17.0.0-0

MathiasWasAlreadyTaken commented 1 year ago

The change in the file libs/angular-i18next/src/lib/models.ts made it worse for us. https://github.com/Romanchuk/angular-i18next/blob/82b33a833af6dd038064ff60975653308a878d88/libs/angular-i18next/src/lib/models.ts#L8 It can't transform with a string array anymore. If a string to be transformed look like this "Send from {{0}} to {{1}}.", you could transform with a string array of two items.

const values[];
values.push("Earth");
values.push("Moon");
this.i18NextPipe.transform('string-key', values);

Now it only takes a dictionary as parameter.

luca-peruzzo commented 1 year ago

"Send from {{0}} to {{1}}."

@Romanchuk

maybe we could typing TOptions like that:

image

MathiasWasAlreadyTaken commented 1 year ago

I read about the breaking change in the latest i18next migration guide. I try and get some time over during the day to test your change, and post the result here.

Romanchuk commented 1 year ago

Renaming StringMap to $Dictionary, and we'll no longer export it. $Dictionary is an internal helper, and there is no reason to expose it. If needed, you can create a copy and reuse it in your project.

export type $Dictionary<T = unknown> = { [key: string]: T };

Romanchuk commented 1 year ago

I did fix types that changed in i18next.

https://github.com/Romanchuk/angular-i18next/releases/tag/v17.0.0-1

https://www.npmjs.com/package/angular-i18next/v/17.0.0-1

@MathiasWasAlreadyTaken

const values[];
values.push("Earth");
values.push("Moon");
this.i18NextPipe.transform('string-key', values);

It won't fix your problem. With previous types PipeOptions actualy detected by typescript as 'any' (it was incorrect). But it meant to be an object (by i18next). i18next can interpolate any key in options object. It did work because array also has access by a key. But i18next doesn't really expect an array to be passed as options. We have to stick to an i18next typings

If you want numbers this should work for you:

{
"1": "Earth",
"2": "Moon"
}

or

const values = {};
values[0]="Earth";
values[1]="Moon";
MathiasWasAlreadyTaken commented 1 year ago

Awesome!

Romanchuk commented 1 year ago

@luca-peruzzo Plz, let me know if 17.0.0-1 is OK for you

luca-peruzzo commented 1 year ago

@luca-peruzzo Plz, let me know if 17.0.0-1 is OK for you

Yep, in my project I always use object interpolation when needed, so no issues for me

Romanchuk commented 1 year ago

I'll release stable version tomorrow