-
Notifications
You must be signed in to change notification settings - Fork 77
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 request: allow sharing messages and terms between bundles #503
Comments
I'm sorry, but I can't understand very well the problem that you said here. I tried the following code: const resourceCommon = new FluentResource(`
-foo = Foo Term
common = Common Message`)
const resourceMain = new FluentResource(`
test = Test { common } { -foo }`)
const bundle = new FluentBundle('lng')
bundle.addResource(resourceCommon)
bundle.addResource(resourceMain)
const testMessage = bundle.getMessage('test')
const testText = bundle.formatPattern(testMessage.value)
console.log(testText) // Test Common Message Foo Term That is, on the child bundle I can get the terms and messages from the parent. Do you want to do something different? |
I have considered doing it this way. Downside of this approach is that changes to parent bundle changes are not reflected in child bundles as messages are just copied. |
Going to close this. Copying messages and terms works |
Sorry I didn't comment earlier. I'd prefer to avoid allowing parent-child hierarchies of bundles. While bundles are mono-lingual, two bundles may be in different languages, have different constructor options (e.g. custom Since messages can reference other messages (and terms), That said, I think it might be a good idea to consider a different lookup model than the current one. Perhaps rather than copying messages into the bundle, we could store references to |
By the way, why |
My thinking is based on my writings in https://discourse.mozilla.org/t/on-message-and-termreferences/53217 and https://discourse.mozilla.org/t/semantics-of-bundles-fallbacks/63107. I'd like for us to fix the problems around language fallbacks, and references with fallbacks. The longer I think about possible solutions, the less the current concept of Bundle helps, and the more I see the localization class concept move to the forefront. Localization would be a cross-language cross-source concept, and language annotations for formatting and selectors would move to entries or patterns. The questions we had about currency formatting in the case of falling back among English locales also makes me wonder if we should actually use the current bundle locale list for formatting, or the full language fallback list. |
That's #218. We've never had a strong use-case for it and most JS apps we've seen don't create more bundles than just a few. I'm happy to revisit it :) |
Global, per locale cache instead of per bundle cache would be really nice to have. Can I create pull request that implements it? |
I am doing some testing having a template # /locales/en/products.ftl
-product-color--11ae039e = Tangerine
product-3050-20-color = { -product-color--11ae039e } on the localized one # locales/zh-CN/products.ftl
-product-color--11ae039e = 柑橘 So I'd think that I am not completely sure this relates to this issue but I'd expect that by just replacing the term on the localized version would be enough to update the message itself? Or perhaps I'm missing something? The translation was generated from Pontoon, which does not add the affected message which uses the term to the commit. So in this case, the workaround was re-declaring the message as below. The only issue is that this could become a bit difficult to maintain. # locales/zh-CN/products.ftl
-product-color--11ae039e = 柑橘
product-3050-20-color = { -product-color--11ae039e } |
I'm working on Vue.js library for fluent.js and wanted to add functionality to split localization into multiple bundles. But I want to be able to share commonly used messages and terms across bundles. Here is simple implementation of a bundle that has this functionality:
https://github.com/Demivan/fluent-vue/blob/7cdd3932130a76b7b270c1113860fb3a3fc8c30f/packages/fluent-vue/src/extendedFluentBundle.ts
This is pretty mush all of it:
Problem with it is that child bundle cannot reference parent terms or messages because resolver does not call
getMessage
method but is accessing_messages
directly:fluent.js/fluent-bundle/src/resolver.ts
Line 205 in f41d910
Can something like this e07d6f7 be added so it is possible to implement this functionality?
Or maybe there is other way of sharing messages and terms?
The text was updated successfully, but these errors were encountered: