Skip to content

Commit

Permalink
fix: not showing localised strings using Chrome
Browse files Browse the repository at this point in the history
* Resolves #831

Fixing not showing localised strings using Chrome by adding internationalisation
tags to `templates/viewer.php` according to the conventional approach in NC to localise apps.

Co-authored-by: Oleksa <[email protected]>
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux and ostasevych committed Aug 22, 2024
1 parent 94268cd commit fbdd1a5
Show file tree
Hide file tree
Showing 3 changed files with 586 additions and 492 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ nbproject
/tests/karma-coverage
.php_cs.cache
node_modules
/vendor
**/vendor/
/build
composer.phar
39 changes: 25 additions & 14 deletions lib/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@
namespace OCA\Files_PDFViewer\Controller;

use OCA\Files_PDFViewer\AppInfo\Application;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;

class DisplayController extends Controller {

/** @var IURLGenerator */
private $urlGenerator;

/**
* @param IRequest $request
* @param IURLGenerator $urlGenerator
*/
public function __construct(IRequest $request,
IURLGenerator $urlGenerator) {
public function __construct(
IRequest $request,
private IURLGenerator $urlGenerator,
private IL10N $l10n,
) {
parent::__construct(Application::APP_ID, $request);
$this->urlGenerator = $urlGenerator;
}

/**
Expand All @@ -37,20 +40,28 @@ public function __construct(IRequest $request,
* @param bool $minmode
* @return TemplateResponse
*/
public function showPdfViewer(bool $minmode = false): TemplateResponse {
public function showPdfViewer(
IAppManager $appManager,
IAppConfig $appConfig,
bool $minmode = false,
): TemplateResponse {
$params = [
'appVersion' => $appManager->getAppVersion(Application::APP_ID),
'enableScripting' => $appConfig->getAppValueBool('enable_scripting', false),
'l10n' => $this->l10n,
'urlGenerator' => $this->urlGenerator,
'minmode' => $minmode
'minmode' => $minmode,
];

$response = new TemplateResponse(Application::APP_ID, 'viewer', $params, 'blank');

$policy = new ContentSecurityPolicy();
$policy->addAllowedChildSrcDomain('\'self\'');
$policy->addAllowedFontDomain('data:');
$policy->addAllowedImageDomain('*');
// Needed for the ES5 compatible build of PDF.js
$policy->allowEvalScript(true);
$policy = (new ContentSecurityPolicy())
->addAllowedFrameDomain('\'self\'')
->addAllowedWorkerSrcDomain('\'self\'')
->addAllowedFontDomain('data:')
->addAllowedImageDomain('*')
// Needed for the ES5 compatible build of PDF.js
->allowEvalScript(true);
$response->setContentSecurityPolicy($policy);

return $response;
Expand Down
Loading

0 comments on commit fbdd1a5

Please sign in to comment.