• Dev
  • problem with translate

Hello, I want to change the translation of one extension into Russian. But an error occurs:

Flarum encountered a boot error (RuntimeException)
Language packs must define "extra.flarum-locale.code" and "extra.flarum-locale.title" in composer.json.
thrown in C:\OSPanel2\domains\mainforum\vendor\flarum\core\src\Extend\LanguagePack.php on line 52

Can you tell me how to solve my problem?
Showing you composer.json of my extension:

{
  "name": "studio/deeprussian",
  "description": "Updated russian language package",
  "keywords": [
    "extension",
    "flarum",
    "russian",
    "language",
    "locale",
    "localization",
    "translation"
  ],
  "type": "flarum-extension",
  "license": "0BSD",
  "require": {
    "flarum/core": "^0.1.0-beta.8"
  },
  "suggest": {
    "marketplace/flarum-l10n-core-russian": "Flarum Russian language pack.",
    "marketplace/flarum-l10n-ext-russian": "Flarum Russian language pack.",
    "fof/byobu": "Byōbu"
  },
  "authors": [
    {
      "name": "studio",
      "email": "yandex.ru",
      "role": "Developer"
    }
  ],
  "autoload": {
    "psr-4": {
      "Studio\\DeepRussian\\": "src/"
    }
  },
  "extra": {
    "flarum-extension": {
      "title": "Deep Russian",
      "icon": {
        "image": "icon.svg",
        "backgroundColor": "#f3f6f9",
        "backgroundSize": "cover",
        "backgroundPosition": "center"
      }
    },
    "flarum-locale": {
      "code": "ru",
      "title": "Русский"
    },
    "flagrow": {
      "discuss": ""
    }
  }
}

my extend. php:

<?php

return new Flarum\Extend\LanguagePack();

    karman what's your development setup? Are you editing an existing language pack or creating a new one? Are you using a workbench/packages folder with Composer?

    If you use a workbench/packages folder and recently updated composer.json, you might have to remove and re-add the package to update Composer's cached version of the file.

      clarkwinkelmann I did exactly as you said, but there is a new error. now, when I go to my forum, the following appears on the screen HTTP ERROR 500

      clarkwinkelmann maybe change the extend.php like this:

      <?php
      namespace Karman\DeepRussian;
      
      use Flarum\Extend;
      
      return [
          new Extend\Locales(__DIR__ . '/resources/locale')
      ];

        karman I was also surprised that the extender wasn't in an array, but Flarum itself does not use an array in the English language pack so I doubt this is an issue.

        What's the 500 error message? Enable Flarum debug mode in config.php and check Flarum log files as well as the webserver log files.

          clarkwinkelmann

          PHP Fatal error: Uncaught RuntimeException: Expected to find "/locale" directory in language pack. in C:\OSPanel2\domains\mainforum\vendor\flarum\core\src\Extend\LanguagePack.php:72
          this problem is found in logs, but I don't understand why this error occurs. Maybe you know?

            karman check how the English pack organizes its files https://github.com/flarum/lang-english

            I believe most language packs use the LanguagePack extender without any constructor parameter. We can see the value defaults to /locale in https://github.com/flarum/core/blob/master/src/Extend/LanguagePack.php in that file I can also see that the path to the extension is prepended to the given file.

            So I see two solutions: don't specify a constructor parameter, and place your files in <extension>/locale. Or specify '/resources/locale' as the parameter (without __DIR__)

              clarkwinkelmann Your option worked! But a new problem has arisen. My translation doesn't show up on the forum, although I seem to have done everything as described in the documentation and in the example of the English package. I just created an extension, wrote my yml file with translation, made composer require and plugged my extension in admin panel, then cleared the cache. But still my translation doesn't work, although I checked my yml many times. What could be the problem?

                karman does the language switcher appear and have you selected the other language?

                You can also set 'debug' => true in config.php so Flarum reloads translations on every request, this removes the need to clear the cache during testing.

                If that doesn't help, also check the yml filenames are correct, because the files are conditionally loaded when the corresponding extension is enabled (and core.yml is always loaded)

                  clarkwinkelmann But the switch should not appear, as this is not a full language pack for Russian, but simply an addition to the existing one. Also, I have checked that the names are correct, and they are definitely spelled correctly. Could there be an error in something else?