foundation / panini

A super simple flat file generator.
Other
592 stars 104 forks source link

Set a default language #136

Closed kekkorider closed 6 years ago

kekkorider commented 6 years ago

I'm developing a website with 2 languages (Italian and English) but I would like to export all the Italian pages to the root folder instead of the /dist/it folder and also the entire /dist/en folder to the root, in order to be able to reach the website from www.mywebsite.com and www.mywebsite.com/en.

Is there a way to do so?

gakimball commented 6 years ago

Not currently! But that makes sense. We could add an option like defaultLocale that copies a specific locale to the root folder.

kekkorider commented 6 years ago

That would be great! Version 2 works really well but how it exports translated pages is a bit "unconvenient" at the moment.

Anyway, I found a custom solution with another gulp package, I'll post it here during the weekend so other people don't have to get crazy.

Thanks!

gakimball commented 6 years ago

Version 2 works really well but how it exports translated pages is a bit "unconvenient" at the moment.

Any other ways you think it could be improved?

kekkorider commented 6 years ago

I'll try to be as clear as possible.

At the moment Panini v2 exports the pages into the /dist/[LANG] folder; in my opinion this is not the typical use case because a website with multiple languages has the default language in the root folder and all the other languages under their respective subfolders.

At the moment the folder structure looks like this:

A possible solution might be moving all the content inside the /dist/[DEFAULT_LOCALE] folder into the /dist folder, so that when I visit the website (or the dev server starts) I can see my website into the default language.

This is what I'm actually doing with my project:

  1. Replace all the relative URLs of the pages inside the /it folder removing the initial ../ and move them up one folder, all using the gulp-url-replace plugin
  2. Delete the /dist/it folder

This of course can be done with a bit of custom work, but it would be great if Panini could handle it by itself.

[EDIT] This would be the exact behavior of the defaultLocale option you mentioned.

Vlasterx commented 6 years ago

This is the way I have created one multilingual site with Panini - www.ilicdent.tom

I have explained on forums the process for that in this topic http://foundation.zurb.com/forum/posts/49731-multilingual-website-and-paninis-built-in-root-variable

gakimball commented 6 years ago

[EDIT] This would be the exact behavior of the defaultLocale option you mentioned.

@kekkorider Yep, I think we're in agreement on how it should be implemented 👍

gakimball commented 6 years ago

Implemented in 85cef154e6719764401b9d2dc1b81ea6c1c0b73a, can you see if this works the way you'd expect? Just add "defaultLocale": "it" to your Panini config in package.json.

kekkorider commented 6 years ago

@gakimball excellent, it works like a charm!

I tested a bit adding subfolders and random stuff, all paths are correct and nothing breaks, also the {{root}} variable behaves as it should.

Side note: the defaultLocale option must be added to the panini call in gulpfile.babel.js, not in package.json.

Thanks a lot, this will save me a lot of time in future projects!

gakimball commented 6 years ago

Side note: the defaultLocale option must be added to the panini call in gulpfile.babel.js, not in package.json.

Ah right, yeah. You can actually do either, the package.json method will be more for people using the CLI.

Glad I could help! 👍

illycz commented 6 years ago

2.0.0-alpha.2

defaultLocale not working for me.

My settings:

gulp.task('views', () => {
  panini()('app', {
    'defaultLocale': 'cs'
  })
    .pipe(gulp.dest('.tmp'))
    .pipe(reload({stream: true}));
});

My index page is still in cs subfolder.