adamduncan / eleventy-plugin-i18n

Eleventy plugin to assist with internationalization and dictionary translations
MIT License
103 stars 10 forks source link

Feature Request: Leverage the data cascade for per-page contextual localisations #23

Open chriskirknielsen opened 1 year ago

chriskirknielsen commented 1 year ago

Hi there,

I like this plugin but ran into issues: I wanted to be able to add localised strings from context. My reasoning behind not adding those strings into a global data file for each language is that longform content is a bit of a pain to organise.

For example, if a layout page (say your typical /about/ page) that needs a particular string localised that isn't within the content itself but a component outside the main layout, you might not want to have all that stuff in your en.json file and whatnot. By adding the translation within the page itself, you can keep your page's localised content contained within the same file. A minor convenience but in my case, it makes a lot of sense.

I have worked this idea into PR #24, let me know what you think.

Note that I nested the additional data under page to prevent key collisions. Prefixing with an underscore or setting a plugin option to a specific key might be a better idea, but keeping it simple for now.

I hope this all make sense, and I can provide a more fleshed out example if interested!

adamduncan commented 1 year ago

@chriskirknielsen Thank you for the suggestion and PR here. Apologies I wasn't more proactive in responding to this at the time. I hope you've found use in having forked this feature into what you're working on.

I definitely think this idea adds value, and would like to consider it alongside the broader open issues/requests (see comment re: project status), whether that's merging this as part of a minor version update, or integrating into a more fundamental rethink for a v1.0.0 release.

chriskirknielsen commented 1 year ago

@adamduncan No worries! I did get my own solution running in the meantime, but it doesn't feel very clean despite being quite functional.

And that sounds like a plan! Feel free to ping me to discuss this if you'd like, happy to provide insight or feedback. There's probably also lots of room for improvement in my approach so taking time to consider it is the wisest option.