Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gearsdigital committed Nov 27, 2021
0 parents commit fad1204
Show file tree
Hide file tree
Showing 28 changed files with 3,321 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = {
extends: ["plugin:vue/recommended", "plugin:prettier-vue/recommended", "prettier"],

settings: {
"prettier-vue": {
// Settings for how to process Vue SFC Blocks
SFCBlocks: {
/**
* Use prettier to process `<template>` blocks or not
*
* If set to `false`, you may need to enable those vue rules that are disabled by `eslint-config-prettier`,
* because you need them to lint `<template>` blocks
*
* @default true
*/
template: true,

/**
* Use prettier to process `<script>` blocks or not
*
* If set to `false`, you may need to enable those rules that are disabled by `eslint-config-prettier`,
* because you need them to lint `<script>` blocks
*
* @default true
*/
script: true,

/**
* Use prettier to process `<style>` blocks or not
*
* @default true
*/
style: true,
},
usePrettierrc: true,
fileInfoOptions: {
withNodeModules: false,
},
},
},

rules: {
"prettier-vue/prettier": [
"error",
{
// Override all options of `prettier` here
// @see https://prettier.io/docs/en/options.html
printWidth: 100,
singleQuote: false,
semi: true,
trailingComma: "es5",
bracketSameLine: true,
},
],
},
};
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: RELEASE
on:
push:
branches:
- main

jobs:
release:
name: Release
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install
run: npm install

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.PAT_SEMANTIC_RELEASE }}
run: npx semantic-release
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# OS files
.DS_Store
.iml
.idea

# npm modules
/node_modules

# Parcel cache folder
.cache

# Composer files
/vendor
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
coverage
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
63 changes: 63 additions & 0 deletions api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

use Kirby\Data\Json;
use Kirby\Filesystem\Dir;
use Kirby\Filesystem\F;
use Kirby\Http\Response;

$contentRoot = kirby()->root('content');
$path = $contentRoot.DS.'localizer';
$localisations = $contentRoot.DS.'localizer'.DS."localisations.json";

return [
'routes' => [
[
'pattern' => '/localizer/translations',
'method' => 'get',
'action' => function () use ($path) {
try {
$files = Dir::read($path);
$data = [];

foreach ($files as $file) {
$content = F::read($path.DS.$file);
if (F::is($file, 'json')) {
$data[] = Json::decode($content);
}
}

return Response::json($data);
} catch (Exception $exception) {
return Response::json([]);
}
},
],
[
'pattern' => '/localizer/translations',
'method' => 'post',
'action' => function () use ($path) {
$translations = kirby()->request()->body()->data();
$languages = [];

foreach ($translations as $translation) {
$id = $translation['language']['id'];
Json::write($path.DS."$id.json", $translation);

// save language id for deletion check
$languages[] = $id;
}

// delete removed languages groups
$files = Dir::read($path);
foreach ($files as $file) {
$filename = F::name($file);
if (!in_array($filename, $languages)) {
F::remove($path.DS.$file);
}
}

return Response::json($translations);
},
],
],
];
24 changes: 24 additions & 0 deletions areas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

return [
'panel-localizer' => function () {
return [
'label' => 'Localizer',
'icon' => 'globe',
'menu' => true,
'link' => 'panel-localizer',
'views' => [
[
'pattern' => 'panel-localizer',
'action' => function () {
return [
'component' => 'k-panel-localizer-area',
'title' => 'Localize Panel Translations',
'props' => [],
];
},
],
],
];
},
];
Empty file added changelog.md
Empty file.
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "gearsdigital/localizer-for-kirby",
"description": "A plugin to override _Panel_ and _Plugin_ translations.",
"version": "1.0.0",
"license": "MIT",
"type": "kirby-plugin",
"authors": [
{
"name": "Steffen Giers",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.4",
"getkirby/composer-installer": "^1.1"
},
"autoload": {
"psr-4": {
"gearsdigital\\localizer\\": "src/"
}
},
"config": {
"optimize-autoloader": true,
"sort-packages": true
}
}
36 changes: 36 additions & 0 deletions hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Kirby\Data\Json;
use Kirby\Filesystem\Dir;
use Kirby\Filesystem\F;

return [
'system.loadPlugins:after' => function () {
$contentRoot = kirby()->root('content');
$path = $contentRoot.DS.'localizer';
$files = Dir::read($path);
$translations = [];

foreach ($files as $file) {
$filePath = $path.DS.$file;
if (!F::exists($filePath)) {
return;
}

$content = Json::read($filePath);
if (F::is($file, 'json')) {
if (is_array($content['translations']) && count($content['translations']) > 0) {
$translations[$content['language']['id']] = array_map(function ($arr) {
if (array_key_exists('override', $arr) && $arr['override']) {
return [$arr['key'] => $arr['override']];
}

return $arr;
}, $content['translations'])[0];
}
}
}

kirby()->extend(['translations' => $translations], kirby()->plugin('gearsdigital/kirby-panel-localizer'));
},
];
1 change: 1 addition & 0 deletions index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fad1204

Please sign in to comment.