Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flarum Beta 16 #1

Merged
merged 3 commits into from Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
js/package-lock.json
js/node_modules/
vendor/
composer.lock
47 changes: 46 additions & 1 deletion extend.php
Expand Up @@ -6,5 +6,50 @@
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Extend;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;

return new Flarum\Extend\LanguagePack();
$settings = app(SettingsRepositoryInterface::class);
$lang = $settings->get('flarumes.mode');
$mode = empty($lang) ? 'es-ES-formal' : $lang;

return [
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js'),

(new Extend\Event)
->subscribe(SwitchLanguageEvent::class),

(new Flarum\Extend\LanguagePack('/locale/' . $mode . '/'))
];

class SwitchLanguageEvent
{
protected $settings;
protected $container;

public function __construct(SettingsRepositoryInterface $settings, Container $container)
{
$this->settings = $settings;
$this->container = $container;
$this->setLanguage($this->settings->get('flarumes.mode'));
}

public function subscribe($events)
{
$events->listen(Saving::class, [$this, 'handleSaving']);
}

public function handleSaving(Saving $event)
{
$this->setLanguage($this->settings->get('flarumes.mode'));
}

private function setLanguage($lang = null)
{
$mode = empty($lang) ? 'es-ES-formal' : $lang;
new Flarum\Extend\LanguagePack('/locale/' . $mode . '/');
$this->container->make('flarum.locales')->clearCache();
}
}
1 change: 1 addition & 0 deletions js/admin.js
@@ -0,0 +1 @@
export * from './src/admin';
2 changes: 2 additions & 0 deletions js/dist/admin.js

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

1 change: 1 addition & 0 deletions js/dist/admin.js.map

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

16 changes: 16 additions & 0 deletions js/package.json
@@ -0,0 +1,16 @@
{
"private": true,
"name": "@flarumes/lang-spanish",
"dependencies": {
"flarum-webpack-config": "0.1.0-beta.10"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"devDependencies": {
"flarum": "^0.1.0-beta.16",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
}
}
16 changes: 16 additions & 0 deletions js/src/admin/index.js
@@ -0,0 +1,16 @@
import { extend } from 'flarum/common/extend';
import app from 'flarum/common/app';

app.initializers.add('flarumes-lang-spanish', () => {
app.extensionData.for('flarumes-lang-spanish')
.registerSetting({
setting: 'flarumes.mode',
type: 'select',
label: 'Preferencia',
options: {
'es-ES-informal': 'España (informal)',
'es-ES-formal': 'España (formal)'
},
default: 'es-ES-formal'
});
});
3 changes: 3 additions & 0 deletions js/webpack.config.js
@@ -0,0 +1,3 @@
const config = require('flarum-webpack-config');

module.exports = config();
File renamed without changes.
2 changes: 2 additions & 0 deletions locale/core.yml → locale/es-ES-formal/core.yml
@@ -1,4 +1,6 @@
# Translations in this namespace are used by the admin interface.
core:

admin:

# These translations are used in the placeholder Add Extension modal dialog.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions locale/es-ES-informal/config.js
@@ -0,0 +1,47 @@
dayjs.locale({
name: 'es-ES',
weekdays : 'Domingo_Lunes_Martes_Miércoles_Jueves_Viernes_Sábado'.split('_'),
weekdaysShort: 'Dom_Lun_Mar_Mié_Jue_Vie_Sáb.'.split('_'),
weekdaysMin: 'Do_Lu_Ma_Mi_Ju_Vi_Sá'.split('_'),
months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
monthsShort: 'Ene_Feb_Mar_Abr_May_Jun_Jul_Ago_Sep_Oct_Nov_Dic'.split('_'),
weekStart: 1,
yearStart: 4,
formats: {
LT : 'HH:mm',
LTS : 'HH:mm:ss',
L : 'DD/MM/YYYY',
LL : 'D [de] MMMM [de] YYYY',
LLL : 'D [de] MMMM [de] YYYY [a las] HH:mm',
LLLL : 'dddd, D [de] MMMM [de] YYYY [a las] HH:mm'
},
calendar : {
sameDay: '[Hoy a] LT',
nextDay: '[Mañana a] LT',
nextWeek: 'dddd [en] LT',
lastDay: '[Ayer en] LT',
lastWeek: function () {
return (this.day() === 0 || this.day() === 6) ?
'[Ultimo] dddd [a las] LT' : // Saturday + Sunday
'[Ultima] dddd [a las] LT'; // Monday - Friday
},
sameElse: 'L'
},
relativeTime: {
future : 'en %s',
past : 'hace %s',
s : 'unos segundos',
m : 'un minuto',
mm : '%d minutos',
h : 'una hora',
hh : '%d horas',
d : 'un día',
dd : '%d días',
M : 'un mes',
MM : '%d meses',
y : 'un año',
yy : '%d años'
},
ordinalParse: /\d{1,2}º/,
ordinal: n => `${n}.`
})