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

(De)serialize FluentArgs #374

Open
TheCataliasTNT2k opened this issue Nov 25, 2024 · 4 comments
Open

(De)serialize FluentArgs #374

TheCataliasTNT2k opened this issue Nov 25, 2024 · 4 comments

Comments

@TheCataliasTNT2k
Copy link

Is there a way, to store FluentArgs in a database or file?
If not, could we get an implementation for serde Serialize and serde Deserialize?

This would allow said feature to create a non translated string and translate it later.

@alerque
Copy link
Collaborator

alerque commented Nov 25, 2024

It might be reasonable to provide such a trait if we are saddling people with the dependency anyway in fluent-bundle.

In the mean time I can't help but wonder why you don't just serialize your data before you stuff it into FluentArgs instead of afterwards. Wouldn't that make more sense anyway?

@TheCataliasTNT2k
Copy link
Author

The idea is not the store a translated text, but the prepared translation itself.

I want to be able to prepare a text, which could be translated. Later, I want to load this text back into memory and translate it into any language I want (if it exists).

Sure, I could create a custom Container, which just maps &str on &str like FluentArgs does.
When translating, I could convert this container to FluentArgs just as if I only used that.
I will do it this way for now, but I thought, there is already a container for it, so why not use that one?

@alerque
Copy link
Collaborator

alerque commented Nov 25, 2024

Serde isn't yet a run time dependency for fluent-bundle, so this would have to be an optional non-default feature.

I still can't make out what the use case is really. If you have data why can't you just keep it? Or keep a translation. I don't understand what the benefit of storing an intermediary format would be.

@TheCataliasTNT2k
Copy link
Author

TheCataliasTNT2k commented Nov 25, 2024

I want to be able to construct a text dynamically out of multiple translations and their args.
I do not have something like a "blueprint", which I can evaluate when needed, I can only evaluate it, while initially generating the text.

The translated text is needed later, and the language is not known during evaluation of my dynamic text.

I will make an example for you:

Lets say, we have a function, which should generate our text to be shown to the user.
This function will concatenate some strings using newlines like this:

Hello <name>!

Your random number on generating was <random_number>

Some sort like this. Yes, it is actually a constructed example, but it shows my idea.
The text (and the inserted values) may depend on the state of the program during generation.

Now, this should be translateable into another language. This is easy.

But I want to be able to translate this exact text again into another language later.
This should not change the value of <random_number>, so I somehow need to store this.

My current idea is, to store the parts like this (just pseudocode):
$hello: {name: <name>}; $random: {random_number: <random_number>}

But to do this, I either need my own HashMap or FluentArgs needs to be serializeable.

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

2 participants