Giter Site home page Giter Site logo

dionarodrigues / iceberg-gatsby-multilang Goto Github PK

View Code? Open in Web Editor NEW
81.0 5.0 19.0 8.88 MB

πŸš€ A Gatsby starter Internationalization / i18n without third party plugins or packages with Posts and Pages by using markdown and CMS.

Home Page: https://iceberg-gatsby-multilang.netlify.com/

License: MIT License

JavaScript 99.35% Dockerfile 0.65%

iceberg-gatsby-multilang's Introduction

Gitpod Ready-to-Code

Gatsby multi-language starter with CMS

Demo on Netlify

Starter on Gatsby

A starter Internationalization / i18n without third party plugins or packages for Posts and Pages. Different URLs dependending on the language. Focused on SEO, PWA, Image Optimization, Styled Components and more. This starter is also integrate with Netlify CMS to manage all pages, posts and images.

  • Translations by using GraphQL, hooks and context API
  • Content in markdown for pages and posts in different languages
  • General translations for any content
  • Creation of menus by using, jSON, translations and GraphQL
  • Netlify CMS to manage all pages, posts and images
  • Styled Components to styles
  • All important seetings for speedy and optimized images
  • Blog Posts list with pagination
  • Focus on SEO
  • PWA

πŸš€ Getting Started

Assuming Gatsby is installed, run the following commands to install the project:

With gatsby-cli:

$ gatsby new gatsby-multilanguage-site https://github.com/diogorodrigues/iceberg-gatsby-multilang.git

With git clone:

$ git clone https://github.com/diogorodrigues/iceberg-gatsby-multilang.git your-project-name # Clone the project

cd your-project-name

rm -rf .git
yarn install # or npm install
gatsby develop # or yarn run develop

Running gatsby develop you will see the following URLs:

http://localhost:8000
http://localhost:8000/___graphql
http://localhost:8000/admin

File Structure

A quick look at the top-level files and directories you'll see in a Gatsby project.

β”œβ”€β”€ blog
β”‚   β”œβ”€β”€ markdown-file.en.md
β”‚   β”œβ”€β”€ markdown-file.pt.md
β”œβ”€β”€ config
β”‚   β”œβ”€β”€ language-mapping
β”‚   β”œβ”€β”€ menu
β”‚   β”‚   β”œβ”€β”€ en.json
β”‚   β”‚   β”œβ”€β”€ pt.json
β”‚   β”œβ”€β”€ translations
β”‚   β”‚   β”œβ”€β”€ en.json
β”‚   β”‚   β”œβ”€β”€ pt.json
β”‚   β”œβ”€β”€ i18n.js
β”œβ”€β”€ pages
β”‚   β”œβ”€β”€ markdown-file.en.md
β”‚   β”œβ”€β”€ markdown-file.pt.md
β”œβ”€β”€ src
β”œβ”€β”€ static
β”‚   β”œβ”€β”€ admin
β”‚   β”‚   β”œβ”€β”€ config.yml
β”‚   β”œβ”€β”€ assets
β”‚   β”‚   β”œβ”€β”€ img
β”œβ”€β”€ gatsby-browser.js
β”œβ”€β”€ gatsby-config.js
β”œβ”€β”€ gatsby-node.js
β”œβ”€β”€ gatsby-ssr.js
β”œβ”€β”€ wrapPageElement.js

  1. blog and pages directories: All markdown files to generate pages and posts.

  2. config: All language settings: languages, strings, menu... In i18n.js you can set the languages and some others important info

  3. src: Components, hooks, templates and fixed pages (Different of markdown pages, these pages have the same url for all languages and the text content needs to be inserted in config/translations files).

  4. static: Netlify settings and images.

  5. gatsby-browser.js: External files and the layout wrapper setting.

  6. gatsby-config.js: Gatsby plugins.

  7. gatsby-node.js: Logic for generating pages and posts by manipulating GraphQL.

  8. wrapPageElement.js As this component wraps every page (due to the wrapPageElement API) we can be sure to have the locale available everywhere!

About Netlify CMS

You must change the Netlify data "repo" and "site_domain" according your Github repository in static/admin/config.yml.

backend:
    name: github # Local
    # name: git-gateway # Prod
    repo: _owner-name/repo-name_ # Path to your GitHub repository
    branch: master
    site_domain: _site-url_ # If site extists

Realize that you need to use name: github for local development and name: git-gateway for prod environment (netlify)

Important notes:

  • General information for languages are defined in config/i18n.js.
  • The general content translations are located in config/translations and the useTranslations custom hook pulls these translations (via GraphQL query) and inserts them into the pages.
  • The menu items translations are located in config/menu and the useMenu custom hook pulls these translations (via GraphQL query) and inserts them into the pages.
  • ✨ New: Adding corresponding urls are locating in config/language-mapping and the useLanguageMapping custom hook pulls these translations (via GraphQL query) and inserts them into the pages. It is used together with the language switcher so that the page is directed to a page corresponding to the other language.
  • Due to the use of a global layout / context API and the language code passed to all pages (see gatsby-node.js), you know on all pages which language is currently displayed.
  • Blogposts are defined in blog directory and pages are defined in pages directory. The file names are the slug of the posts and pages.
  • A custom component for the tag is implemented - this way links can stay the same for every language, without the need to manually write path prefixes.

Deploy

Deploy to Netlify


πŸ’œ Thanks


This project started based on this solution to create a manner to provide translations, but I added a lots of other solutions based on my projects needs (like menu from GraphQL, markdown for pages, pagination, image optmization, styled components, PWA, CMS and more). Feel free to use this solution if you want. :)

iceberg-gatsby-multilang's People

Contributors

codenamejason avatar dependabot[bot] avatar gstrainovic avatar nagi1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

iceberg-gatsby-multilang's Issues

Route change path bug

When switching language, I often end up with erroneous paths, yielding a blank or 404 page. In both Chrome and Firefox.

http://localhost:3000/pt//blog ->Β When switching from EN version
http://localhost:3000/pt/contato/pt/contato -> when re-clicking on contao in the menu
http://localhost:3000/pt/pt/sobre ->Β when clicking "sobre" in the menu from http://localhost:3000/pt
http://blog/adding-menu-items (set as absolute url - no protocol). -> when switching from the PT version.
I did some test adding new files, but git stash all changes, ran gatsby clean, used the default port, but the issue is still present. It's such a big problem, that I've assume it's project specific, but I've reverted to the initial repo. Is there some hidden cache that is gitignored and not cleared by gatsby clean?

This is happening both in the develop and build versions.

Perhaps it's only affecting localhost? Is this an issue you ran into previously?

Paginated blog posts list routes to homepage when language is changed

The Starter sample contains five blog items which make two pages. When I am on page 1, I can switch between languages and remain on the same page, which is correct. When I am on page 2 and switch to another language, I am routed to the homepage, which is not user-intuitive.
It seems that the Starter requires that a blog post exists in every site language and it sorts them by date, so pagination rules should allow matching the pages.

open an associated blogpost in other languages

maybe it is somehow possible to open the associated pages in the other languages?

if the filename is same then it maybe is easy but when the filenames are different then it should be somehow mapped?

maybe with a filename language mapping json between the translations?

Backend not working on live site hosted on Netlify

Hello, I used your Deploy to Netlify button and everything seems to work great except I can't login to the backend. But when I cloned the repo and viewed the site locally it worked perfectly.

I tried everything I could think of to get it to work on the live site including...

But no matter what I tried, I always got the following screen in a popup after I clicking "login with GitHub" from "/admin" on the live site...
image

I'm about to start over, can you please tell me which of the things I tried was actually necessary if any of them. I'm starting to wonder if Netlify Identity is needed at all.

Anyways can you please help me figure out how to get the backend working on a live site hosted on Netlify?

Thanks,

Chris

Blog post dates are rendered incorrectly.

Hello.

I noticed that on your demo site the blog post dates are being incorrectly rendered.

For example, for the blog post Adding menu items, the date being rendered is 15/10/2019 rather than the DD/MM/YYYY format of 10/15/2019.

Similarly, for the blog post Digital image processing, the date being rendered is 01/04/2019 when it should be 04/01/2019.

This is seen in both en and pt.

Third language breaks a lot of things

I added one more language to the Starter. It broke many things at once:

  • the second page in the Blogs returns 404
  • Blog posts mix up with pages like "contact" and "about"
  • some pictures don't load with blog posts while some do
  • there are multiple warnings during gatsby develop start phase - like "warn You can't use childImageSharp together with en.json β€” use publicURL instead. The childImageSharp portion of the query in this file will return null: undefined"

Not every error is easily reproducible; a restart of gatsby develop may change the behaviour.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.