Skip to content

Commit fad1204

Browse files
committed
first commit
0 parents  commit fad1204

28 files changed

+3321
-0
lines changed

.eslintrc.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
module.exports = {
2+
extends: ["plugin:vue/recommended", "plugin:prettier-vue/recommended", "prettier"],
3+
4+
settings: {
5+
"prettier-vue": {
6+
// Settings for how to process Vue SFC Blocks
7+
SFCBlocks: {
8+
/**
9+
* Use prettier to process `<template>` blocks or not
10+
*
11+
* If set to `false`, you may need to enable those vue rules that are disabled by `eslint-config-prettier`,
12+
* because you need them to lint `<template>` blocks
13+
*
14+
* @default true
15+
*/
16+
template: true,
17+
18+
/**
19+
* Use prettier to process `<script>` blocks or not
20+
*
21+
* If set to `false`, you may need to enable those rules that are disabled by `eslint-config-prettier`,
22+
* because you need them to lint `<script>` blocks
23+
*
24+
* @default true
25+
*/
26+
script: true,
27+
28+
/**
29+
* Use prettier to process `<style>` blocks or not
30+
*
31+
* @default true
32+
*/
33+
style: true,
34+
},
35+
usePrettierrc: true,
36+
fileInfoOptions: {
37+
withNodeModules: false,
38+
},
39+
},
40+
},
41+
42+
rules: {
43+
"prettier-vue/prettier": [
44+
"error",
45+
{
46+
// Override all options of `prettier` here
47+
// @see https://prettier.io/docs/en/options.html
48+
printWidth: 100,
49+
singleQuote: false,
50+
semi: true,
51+
trailingComma: "es5",
52+
bracketSameLine: true,
53+
},
54+
],
55+
},
56+
};

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: RELEASE
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: Release
10+
if: github.ref == 'refs/heads/main'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: 16
22+
23+
- name: Install
24+
run: npm install
25+
26+
- name: Release
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.PAT_SEMANTIC_RELEASE }}
29+
run: npx semantic-release

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# OS files
2+
.DS_Store
3+
.iml
4+
.idea
5+
6+
# npm modules
7+
/node_modules
8+
9+
# Parcel cache folder
10+
.cache
11+
12+
# Composer files
13+
/vendor

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
coverage

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

api.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use Kirby\Data\Json;
4+
use Kirby\Filesystem\Dir;
5+
use Kirby\Filesystem\F;
6+
use Kirby\Http\Response;
7+
8+
$contentRoot = kirby()->root('content');
9+
$path = $contentRoot.DS.'localizer';
10+
$localisations = $contentRoot.DS.'localizer'.DS."localisations.json";
11+
12+
return [
13+
'routes' => [
14+
[
15+
'pattern' => '/localizer/translations',
16+
'method' => 'get',
17+
'action' => function () use ($path) {
18+
try {
19+
$files = Dir::read($path);
20+
$data = [];
21+
22+
foreach ($files as $file) {
23+
$content = F::read($path.DS.$file);
24+
if (F::is($file, 'json')) {
25+
$data[] = Json::decode($content);
26+
}
27+
}
28+
29+
return Response::json($data);
30+
} catch (Exception $exception) {
31+
return Response::json([]);
32+
}
33+
},
34+
],
35+
[
36+
'pattern' => '/localizer/translations',
37+
'method' => 'post',
38+
'action' => function () use ($path) {
39+
$translations = kirby()->request()->body()->data();
40+
$languages = [];
41+
42+
foreach ($translations as $translation) {
43+
$id = $translation['language']['id'];
44+
Json::write($path.DS."$id.json", $translation);
45+
46+
// save language id for deletion check
47+
$languages[] = $id;
48+
}
49+
50+
// delete removed languages groups
51+
$files = Dir::read($path);
52+
foreach ($files as $file) {
53+
$filename = F::name($file);
54+
if (!in_array($filename, $languages)) {
55+
F::remove($path.DS.$file);
56+
}
57+
}
58+
59+
return Response::json($translations);
60+
},
61+
],
62+
],
63+
];

areas.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
return [
4+
'panel-localizer' => function () {
5+
return [
6+
'label' => 'Localizer',
7+
'icon' => 'globe',
8+
'menu' => true,
9+
'link' => 'panel-localizer',
10+
'views' => [
11+
[
12+
'pattern' => 'panel-localizer',
13+
'action' => function () {
14+
return [
15+
'component' => 'k-panel-localizer-area',
16+
'title' => 'Localize Panel Translations',
17+
'props' => [],
18+
];
19+
},
20+
],
21+
],
22+
];
23+
},
24+
];

changelog.md

Whitespace-only changes.

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "gearsdigital/localizer-for-kirby",
3+
"description": "A plugin to override _Panel_ and _Plugin_ translations.",
4+
"version": "1.0.0",
5+
"license": "MIT",
6+
"type": "kirby-plugin",
7+
"authors": [
8+
{
9+
"name": "Steffen Giers",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"php": ">=7.4",
15+
"getkirby/composer-installer": "^1.1"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"gearsdigital\\localizer\\": "src/"
20+
}
21+
},
22+
"config": {
23+
"optimize-autoloader": true,
24+
"sort-packages": true
25+
}
26+
}

hooks.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Kirby\Data\Json;
4+
use Kirby\Filesystem\Dir;
5+
use Kirby\Filesystem\F;
6+
7+
return [
8+
'system.loadPlugins:after' => function () {
9+
$contentRoot = kirby()->root('content');
10+
$path = $contentRoot.DS.'localizer';
11+
$files = Dir::read($path);
12+
$translations = [];
13+
14+
foreach ($files as $file) {
15+
$filePath = $path.DS.$file;
16+
if (!F::exists($filePath)) {
17+
return;
18+
}
19+
20+
$content = Json::read($filePath);
21+
if (F::is($file, 'json')) {
22+
if (is_array($content['translations']) && count($content['translations']) > 0) {
23+
$translations[$content['language']['id']] = array_map(function ($arr) {
24+
if (array_key_exists('override', $arr) && $arr['override']) {
25+
return [$arr['key'] => $arr['override']];
26+
}
27+
28+
return $arr;
29+
}, $content['translations'])[0];
30+
}
31+
}
32+
}
33+
34+
kirby()->extend(['translations' => $translations], kirby()->plugin('gearsdigital/kirby-panel-localizer'));
35+
},
36+
];

0 commit comments

Comments
 (0)