Skip to content

Commit

Permalink
feat: internationalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Sep 18, 2020
1 parent eb42847 commit e1eeb71
Show file tree
Hide file tree
Showing 35 changed files with 339 additions and 64 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ You’ll be asked to provide the following values:
* [Usage](#usage)
* [Options](#options)
* [Plugins](#plugins)
* [Localisations](#localisations)
* [Local development](#local-development)
* [Credits](#credits)
* [Similar projects](#similar-projects)
Expand All @@ -54,6 +55,7 @@ You’ll be asked to provide the following values:
* Bookmarklet to save and share bookmarks
* Publish to different content stores (GitHub and GitLab)
* Support for popular static site generators (Jekyll, Hugo, 11ty)
* Localised to [different languages](#localisations)
* ~~Plugin API~~

## Install
Expand Down Expand Up @@ -179,10 +181,10 @@ To ensure Indiekit’s endpoint can be discovered by Micropub clients (and have

### `application.locale`

The language used in the application interface. Available languages: `en`
The language used in the application interface. See the list of [supported languages](#localisations).

Type: `string`\
*Optional*, defaults to `en`
*Optional*, defaults to system language if supported, else `en` (English)

### `application.mongodbUrl`

Expand Down Expand Up @@ -214,10 +216,10 @@ Type: `Array | URL`\

### `publication.locale`

Your publication’s locale, this value is currently used to format dates.
Your publication’s locale. Currently used to format dates.

Type: `string`\
*Optional*, defaults to value in `application.locale`
*Optional*, defaults to `en` (English)

### `publication.me`

Expand Down Expand Up @@ -463,6 +465,15 @@ The following endpoints are included by default:
* [Jekyll](https://www.npmjs.com/package/@indiekit/preset-jekyll)
* [Hugo](https://www.npmjs.com/package/@indiekit/preset-hugo)

## Localisations

Indiekit has been localised into the following languages:

* `en-US`: English (US)
* `de-DE`: Deutsch

Contributions for other languages are encouraged.

## Local development

```sh
Expand Down
1 change: 0 additions & 1 deletion indiekit.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const github = new GithubStore({

// Application settings
indiekit.set('application.mongodbUrl', process.env.MONGODB_URL);
indiekit.set('application.locale', process.env.LOCALE);

// Publication settings
indiekit.set('publication.me', process.env.PUBLICATION_URL);
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-media/controllers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const filesController = publication => ({
list: async (request, response, next) => {
try {
response.render('files', {
title: 'Uploaded files',
title: response.__('media.files.title'),
files: await publication.media.find().toArray(),
parentUrl: `${publication.mediaEndpoint}/files/`
});
Expand Down Expand Up @@ -49,7 +49,7 @@ export const filesController = publication => ({
);

response.render('file', {
parent: 'Uploaded files',
parent: response.__('media.files.title'),
title: file.properties.filename,
published: file.properties.published,
type: file.properties['post-type'],
Expand Down
6 changes: 5 additions & 1 deletion packages/endpoint-media/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import {uploadController} from './controllers/upload.js';
import {filesController} from './controllers/files.js';
import {queryController} from './controllers/query.js';
import {locales} from './locales/index.js';

export const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand All @@ -31,10 +32,13 @@ export const MediaEndpoint = class {
init(indiekitConfig) {
const {application, publication} = indiekitConfig;

indiekitConfig.addLocale('de', locales.de);
indiekitConfig.addLocale('en', locales.en);

if (application.hasDatabase) {
indiekitConfig.addNavigation({
href: `${this.mountpath}/files`,
text: 'Files'
text: 'media.title'
});
}

Expand Down
10 changes: 10 additions & 0 deletions packages/endpoint-media/locales/de.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const de = {
media: {
title: 'Dateien',
download: 'Download-Datei',
properties: 'Eigenschaften',
files: {
title: 'Hochgeladene Dateien'
}
}
};
10 changes: 10 additions & 0 deletions packages/endpoint-media/locales/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const en = {
media: {
title: 'Files',
download: 'Download file',
properties: 'Properties',
files: {
title: 'Uploaded files'
}
}
};
4 changes: 4 additions & 0 deletions packages/endpoint-media/locales/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {de} from './de.js';
import {en} from './en.js';

export const locales = {de, en};
4 changes: 2 additions & 2 deletions packages/endpoint-media/views/file.njk
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
{% elif type == "video" %}
<video src="{{ url }}" controls>
{% else %}
<a href="{{ url }}" download>Download file</a>
<a href="{{ url }}" download>{{ __("media.download") }}</a>
{% endif %}
{{ summary({
title: "File properties",
title: __("media.properties"),
rows: properties
}) }}
{% endblock %}
4 changes: 2 additions & 2 deletions packages/endpoint-micropub/controllers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const postsController = publication => ({
list: async (request, response, next) => {
try {
response.render('posts', {
title: 'Published posts',
title: response.__('micropub.posts.title'),
posts: await publication.posts.find().toArray(),
parentUrl: `${publication.micropubEndpoint}/posts/`
});
Expand Down Expand Up @@ -50,7 +50,7 @@ export const postsController = publication => ({
);

response.render('post', {
parent: 'Published posts',
parent: response.__('micropub.posts.title'),
title: post.properties.name || capitalize(post.properties['post-type']),
content: post.properties.content,
properties,
Expand Down
6 changes: 5 additions & 1 deletion packages/endpoint-micropub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {fileURLToPath} from 'url';
import {actionController} from './controllers/action.js';
import {postsController} from './controllers/posts.js';
import {queryController} from './controllers/query.js';
import {locales} from './locales/index.js';

export const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand All @@ -31,10 +32,13 @@ export const MicropubEndpoint = class {
init(indiekitConfig) {
const {application, publication} = indiekitConfig;

indiekitConfig.addLocale('de', locales.de);
indiekitConfig.addLocale('en', locales.en);

if (application.hasDatabase) {
indiekitConfig.addNavigation({
href: `${this.mountpath}/posts`,
text: 'Posts'
text: 'micropub.title'
});
}

Expand Down
10 changes: 10 additions & 0 deletions packages/endpoint-micropub/locales/de.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const de = {
micropub: {
title: 'Beiträge',
microformats: 'Microformats für diesen Beitrag',
properties: 'Eigenschaften',
posts: {
title: 'Hochgeladene Dateien'
}
}
};
10 changes: 10 additions & 0 deletions packages/endpoint-micropub/locales/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const en = {
micropub: {
title: 'Posts',
microformats: 'Microformats for this post',
properties: 'Properties',
posts: {
title: 'Published posts'
}
}
};
4 changes: 4 additions & 0 deletions packages/endpoint-micropub/locales/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {de} from './de.js';
import {en} from './en.js';

export const locales = {de, en};
4 changes: 2 additions & 2 deletions packages/endpoint-micropub/views/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
{% endfor %}
{% endif %}
{{ summary({
title: "Post properties",
title: __("micropub.properties"),
rows: properties
}) }}
<details>
<summary>Microformats for this post</summary>
<summary>{{ __("micropub.microformats") }}</summary>
<pre>{{ post.properties.mf2 | dump(2) }}</pre>
</details>
{% endblock %}
4 changes: 2 additions & 2 deletions packages/endpoint-share/controllers/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const shareController = publication => ({
const {content, name, url, success} = request.query;

response.render('share', {
title: 'Share',
title: response.__('share.title'),
content,
name,
url,
Expand Down Expand Up @@ -33,7 +33,7 @@ export const shareController = publication => ({
} catch (error) {
if (error.response) {
response.render('share', {
title: 'Share',
title: response.__('share.title'),
content,
name,
url,
Expand Down
6 changes: 5 additions & 1 deletion packages/endpoint-share/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from 'express';
import path from 'path';
import {fileURLToPath} from 'url';
import {shareController} from './controllers/share.js';
import {locales} from './locales/index.js';

export const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand All @@ -28,9 +29,12 @@ export const ShareEndpoint = class {
init(indiekitConfig) {
const {application, publication} = indiekitConfig;

indiekitConfig.addLocale('de', locales.de);
indiekitConfig.addLocale('en', locales.en);

indiekitConfig.addNavigation({
href: this.options.mountpath,
text: 'Share'
text: 'share.title'
});

indiekitConfig.addRoute({
Expand Down
9 changes: 9 additions & 0 deletions packages/endpoint-share/locales/de.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const de = {
share: {
title: 'Teilen',
name: 'Titel',
content: 'Inhalt',
url: 'URL',
submit: 'Veröffentlichen'
}
};
9 changes: 9 additions & 0 deletions packages/endpoint-share/locales/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const en = {
share: {
title: 'Share',
name: 'Title',
content: 'Content',
url: 'URL',
submit: 'Publish'
}
};
4 changes: 4 additions & 0 deletions packages/endpoint-share/locales/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {de} from './de.js';
import {en} from './en.js';

export const locales = {de, en};
14 changes: 7 additions & 7 deletions packages/endpoint-share/views/share.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
{% block fieldset %}
{{ preview({
title: {
text: "Title",
text: __("share.name"),
for: "name",
value: name
},
text: {
text: "Content",
text: __("share.content"),
for: "content",
value: content
},
url: {
text: "URL",
text: __("share.url"),
for: "url",
value: url
},
Expand All @@ -28,7 +28,7 @@
name: "name",
value: name,
label: {
text: "Title"
text: __("share.name")
}
}) }}

Expand All @@ -37,7 +37,7 @@
name: "content",
value: content,
label: {
text: "Content"
text: __("share.content")
}
}) | indent(8) }}

Expand All @@ -46,7 +46,7 @@
name: "bookmark-of",
value: url,
label: {
text: "URL"
text: __("share.url")
}
}) }}

Expand All @@ -63,6 +63,6 @@
}) }}

{{ button({
text: "Publish"
text: __("share.submit")
}) }}
{% endblock %}
5 changes: 3 additions & 2 deletions packages/indiekit/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {MicropubEndpoint} from '@indiekit/endpoint-micropub';
import {ShareEndpoint} from '@indiekit/endpoint-share';
import {authenticate} from '../middleware/authentication.js';
import {indieauth} from '../middleware/indieauth.js';
import {locales} from '../locales/index.js';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packagePath = path.join(__dirname, '..', 'package.json');
Expand All @@ -22,7 +23,7 @@ const application = {
shareEndpoint
],
hasDatabase: false,
locale: 'en',
locales,
mongodbUrl: false,
middleware: {
authenticate,
Expand All @@ -41,7 +42,7 @@ const application = {

const publication = {
categories: [],
locale: application.locale,
locale: 'en',
me: null,
postTemplate: null,
postTypes: [],
Expand Down
Loading

0 comments on commit e1eeb71

Please sign in to comment.