-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Refactor i18n #924
Comments
👍
|
My following question may result from a lack of Ruby and or Rails knowledge, but is there an easy way to create different content structures for different languages? Basically dynamic content depending on the users language. Something like: if i18n.locale?(:russian)
# insert russian specific content
end If not, a template helper would be great, if you're about to refactor i18n. |
@j4zz This should work currently. We'll add a better named
|
Great, thanks! |
👍 this sounds great. We have a large (~400 page) site, which needs to support several locales. We ended up writing our own plugin to handle localisation. Our structure looks something like:
(Files in The biggest issue for us is that we want to have the ability to specify one page as being present in several (but not necessarily all) locales. A way to handle that would be nice. Perhaps, the ability to alternatively specify a list in the localizable: en,fr Having have two alternative ways to localize a file (locale in extension or frontmatter) might be confusing, though. Do non-localized files output to the root or to every single locale folder, but they are the same? We deploy each locale as a self-contained directory, so the latter option suits us. I'm not sure that suits the majority of people, though. What about making this an option, or something that can be overridden in a plugin without too much effort? Do non-html files need to be localized? Strings in JS? I can't speak for anyone else, but this isn't an issue for us, at least. You could always append Really like the sound of this. Happy to help contribute here. |
FYI @Aupajo #848 is a request for a simular implementation of the same feature. With the proposed Do non-localized files output to the root or to every single locale folder, but they are the same?Outputting non-localized files to each locale is never what we would want. For the case when we need to output a file to multiple locales that it has not been translated for we use a fallback scheme. Basically setup a fallback map:
Then we override the Do non-html files need to be localized? Strings in JS?Non-HTML files should be localized, we have a bit of hack going to localize some JSON strings files for an Ember.js app. Also, we sometimes build things other than websites, like a large number of email templates, where we need both .html and .txt output. Being able to configure what file extensions get localized from the activate call would be ideal. |
I think The reason for allowing both frontmatter and config.rb to configure which files are localized is one of scope. Changing an entire folder of files' frontmatter is annoying, but something like the following might be nice:
Now sure about the syntax or naming, but the idea seems nice. @pulletsforever If we make the entire project localizable, then it would result in a copy of every JS file in every locale... which is probably not what you want. Maybe we have something like this:
|
@tdreyno yes, that looks good. |
@tdreyno 👍 |
Another possible use case for non-HTML files is images and fonts. Our product has a localized UI by country, so images are often localized by country. It would be nice to specify:
And have it pick up product.fr.jpg if present when the locale is The In the case of background-images we use a locale wrapper in SASS that picks up the lang attribute on the HTML element, i.e.:
A SASS mixin was written that automatically wrapped declarations when the appropriate file names were found would also be a good fit. It could even be extended to fonts, where you would likely want a different font for non-Latin based languages. |
Just brought to my attention: Again the |
Answers to the questions as well as my own thoughts (further below): Do non-localized files output to the root or to every single locale folder, but they are the same? Does any of this seem natural to Rails users? Do non-html files need to be localized? Strings in JS?
Additional thoughts: 1. It would be neat if one could set the load_path via the I18n extension. We currently do this manually:
2. Our proxy pages don't get the correct locale even though they have a locale specific in their filename (which we solved by setting it again inside the block, shown below). Though this could be a misunderstanding on our part too.
3. We couldn't get links to be locale_aware. Again, this can us doing it plain wrong. Anyway, here is how we solved it:
4. A 5. Access to the value of |
In terms of using translated strings in Javascript, that's something I've done a lot of recently. A lot like @sandstrom I ended up just making a file called
And in |
Something else that just came up is referring to the pages in a language-agnostic way. For example, it's currently hard for me to ask Middleman for "the french version of page how-it-works". I've been prying and digging for a way to do this simply, but I'm not finding. There is simply no map of which pages got translated into what. Let's come back to my example of 'how-it-works'. I have page 'how-it-works.html.haml', localized for both fr+en. I'm making a nav bar, and I want to say "go to your version of how-it-works". Now my English pages are unprefixed ('/how-it-works') and French are ('/fr/fonctionnement'). Without a helper, I will have to test for english to see whether I should add a prefix, and then go through the i18n file for paths. And I have to do this for every occurence in my views. Linking to stuff right now is a bit hard. Edit: I just saw @sandstrom's comment now, which talks about links. Sorry about that. Related concern: the lang switch link. Right now, there's no obvious way to say "link to this same page, but in that other language." Again, a locale mapping would solve that. |
@joallard Very good idea and should be simple to add that metadata to each localized resource. |
👍 @joallard Yeah. Someone ran into this issue on the forums a little while back. I gave him a solution, but it relied on making assumptions on how URLs are formed. http://forum.middlemanapp.com/t/i18n-list-of-language-siblings-and-links-to-them/978/2 |
I've tried leveraging the current implementation of i18n and was discouraged with the fact that it's implemented very differently for basic Middleman vs Middleman Blog. When i thought about it i came to a conclusion that this can't be considered a fault of the i18n module. The very fact of distinction between Middleman and Middleman Blog brings a lot of trouble. My question is: have you considered integrating Blog into basic Middleman and introducing a unified implementation for both basic pages and blog articles? |
What specific functionality do you think should be brought over to Middleman from middleman-blog? What specifically do you see as differences between the two? I don't use the |
Without the troubles of bringing blog and core together, I think that just uniformizing the two with the same config parameters would be nice. I have yet to try out blog in multiple languages, but that's what I'm getting from Andrey's comment. @lolmaus, would you bring us up to speed with (a) the differences between configuring i18n in core vs. blog, and (b) what kind of syntax/config you'd ideally expect with M-blog? |
Hi! Sorry for not replying in time. i18n-related inconsistencies between middleman and middleman-blog
The story of my i18n woesI decided to build a language switcher partial for my Middleman website. For every page, the switcher should point to the same page in other languages, not just to the title page. If the page is not available, it should produce a greyed out language item. I like the To create the paginator, i needed to be able to do two things:
The only way to make it happen that i managed to find was to work with pages' source paths. I had no option but to make an assumption that all URLs on my site start with a two-character language prefix and a slash (except for the default language). So to generate links to other pages and checking that they exist i remove first three characters from the current page's source path (except for the default language) and attach the prefix of a different language. This works, but it enforces a terrible directory scheme. Static pages go to Why i think middleman and middleman-blog should be mergedThe matter is that middleman-blog is not just for blogs. It fills in the functionality that lacks in default middleman implementation. Here's what middleman-blog does for me:
Neither of those features is limited to the "blog" concept. All of them are universal for "content", and all websites are about content. If i were to decide, i would rename middleman-blog to middleman-content. When you master using middleman-blog, it becomes almost pointless to use the vanilla middleman pages functionality. Basically, i still use vanilla pages only because middleman-blog forces me to manually provide dates for each page. That's why i suggest for middleman maintainers to consider merging middleman-blog into middleman 4.0, producing a revamped API. |
Is there currently been worked on? Nice to see some progress in the meanwhile. 👍 |
v4.0 is now being worked on. This feature hasn't started being refactored yet, but hopefully it will within a month or so as we finish a lot of housecleaning in the core codebase. |
Completely agree with @lolmaus about merging middleman-blog into middleman. My thoughts on this:
I think it would be more logical to move the I would also like suggest a more unified approach on multi-language sites. For example:
These are my thoughts on (localized) content. Please check if they would fit in technically/strategically. Keep up the great work! |
@rensverschuren I'm not really following all that. Would you be able to make an example repo with the file structure and optimal |
This is a proposal for refactoring how i18n works in Middleman v4.
First, we remove the magical
localizable
folder.When
i18n
is activated, all html files in source are localized by default into as many languages as the user specifies. These files are output into their own folders (en, es, fr) as usual.To be more specific, there are additional options:
Naming a file with the locale will target only that specific output folder. For example:
about.fr.html.erb
will only output tofr
.Adding
localizable: false
to the front matter will not move the file during build and will have the default locale set.Adding a glob or a proc to the activation can mass skip localization:
Questions:
Tracking:
localizable
folderlocalized
front matterfilter
to extension to specify which files insource
are localized.link_to
, etc) aware ofi18n
The text was updated successfully, but these errors were encountered: