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

Enh/content language #175

Merged
merged 4 commits into from
Aug 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use humhub\components\Controller;
use humhub\modules\content\models\Content;
use humhub\modules\rest\components\auth\ImpersonateAuth;
use humhub\modules\rest\components\behaviors\LanguagePickerBehavior;
use humhub\modules\rest\components\User as UserComponent;
use humhub\modules\rest\components\auth\JwtAuth;
use humhub\modules\rest\controllers\auth\AuthController;
Expand Down Expand Up @@ -81,6 +82,9 @@ public function behaviors()
]]
),
],
'languagePicker' => [
'class' => LanguagePickerBehavior::class,
]
], parent::behaviors());
}

Expand Down
28 changes: 28 additions & 0 deletions components/behaviors/LanguagePickerBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace humhub\modules\rest\components\behaviors;

use Yii;
use yii\base\Behavior;
use yii\helpers\ArrayHelper;
use yii\web\Controller;

class LanguagePickerBehavior extends Behavior
{
public function events()
{
return [
Controller::EVENT_BEFORE_ACTION => 'pickLanguage',
];
}

public function pickLanguage()
{
if (
empty(Yii::$app->request->acceptableLanguages) &&
$userLanguage = ArrayHelper::getValue(Yii::$app->user->identity, 'language')
) {
Yii::$app->language = $userLanguage;
}
}
}
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

0.10.2 (unreleased)
----------------------
- Enh #175: User language will be used by default

0.10.1 (July 31, 2024)
----------------------
- Enh #173: Added possibility to change `created_at` of `content`
Expand Down
4 changes: 4 additions & 0 deletions docs/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Following RESTful API endpoints are available.

The base url for all APIs is: `https://yourhost/api/v1/`

**Language**

Logged-in user's language will be used. Can be overwritten by `Accept-Language` header.


**Core APIs:**

Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": [
"api", "rest"
],
"version": "0.10.1",
"version": "0.10.2",
"homepage": "https://github.com/humhub/rest",
"humhub": {
"minVersion": "1.16"
Expand Down
Loading