MyBB Community Forums

Full Version: Mybb English Language JSON
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright, so I spent today doing a rough version of a JSON object containing all of the MyBB Language Files (And their content).

What is missing?
  • customhelpdocs.lang.php and customhelpsections.lang.php are not included (They are by default 'empty')

The JSON includes the admin files.

You can find it here:
http://mathiasm.com/mybb_language.json

The objects are, respectively, inside "/" and "/admin/", which is the file path where the files are. Alle objects imitating a language file, includes location (Ironically the same?) and a variables object which holds all the key->value pairs of the MyBB language variable -> English Value. I created it like this because I have an intention to use it in this format, I'm in no way pro at creating or using JSON, this is probably going to be the first and only time I ever create a JSON object with more than 5k lines.. ouch.

I really don't think it will be of use to any person on here, but felt like what the heck, spent a good amount of time reformatting the 100 files. I am trying to develop a simple interface that allows users to create their own translations and publish them on a shared library for other users. (Download will export it to the necessary files and format).

If I ever finish it, I will share the website here so that everyone can benefit. At the moment it's a rough sketch, and I've only just finished the initial design. And honestly, now that I look at the idea I can't really see how this will actually be easier since it's unimaginably close to just manually editing all the files, this time it's just text inputs instead.

Well, at least it is good for training my PHP file handling...

Happy MyBB folks, good luck with your translations.
Appreciate your effort and spending such time for your practice.
Not being rude, but just 2 lines of PHP code can do that in a flash what you have done 'spending a good amount of time'.
(2020-12-04, 03:00 AM)effone Wrote: [ -> ]Appreciate your effort and spending such time for your practice.
Not being rude, but just 2 lines of PHP code can do that in a flash what you have done 'spending a good amount of time'.

Could you share the code of 2 lines with me? Since I need it in this exact format and as I said, I'm not good at working with JSON. I'd appreciate the code instead of just the lecture...

Edit:

I tried json encoding the $lang object, but the result is far from 'ideal', and working with it to create an optimal json object will require lots of work. I really would love to know your method, so that I can easilier achieve what I need for future iterations. (Also since I need the files and what they contain to be part of the JSON object)

Edit:

What came closest to a proper result was doing something similar to this:

<?

define('IN_MYBB', 1); require "./global.php";

$old_lang = (array) $lang;

$lang->load("announcements");

$current = array_diff((array) $lang, $old_lang);

print_r($current);

But tbh, this is again, far from ideal. I couldn't manage to find a way to easily just load all languages, and even by doing this, I would have to also get their location and create an array of the same name.
(2020-12-04, 03:00 AM)effone Wrote: [ -> ]...

If you know how to do it effortlessly could you please share it with me? I will use my JSON object to start the development of a translation panel, but if you have an easier way of achieving the same data or similar data object with less effort, I'd be able to scale it much better.

Please lmk.
Try:
<?php

$path = 'inc/languages/english';
$outputFile = 'mybb-english.json';

$strings = [];

$iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
);

foreach ($iterator as /** @var SplFileInfo $item */ $item) {
    $directory = substr($item->getPath(), strlen($path) + 1); // strip $path

    if ($directory === false) {
        $directory = '/';
    }

    if (preg_match('/\.lang\.php$/', $item->getFilename())) {
        $file = substr($item->getFilename(), 0, -9); // strip '.lang.php'

        require $item->getPathname();

        if (!isset($l)) {
            $l = [];
        }

        /** @var array<string, string> $l */

        $strings[$directory][$file] = $l;
        unset($l);
    }
}

file_put_contents(
    $outputFile,
    json_encode($strings, JSON_PRETTY_PRINT)
);


Also, a related tool: https://community.mybb.com/thread-227986.html
(2020-12-06, 02:43 PM)Devilshakerz Wrote: [ -> ]Try:
<?php

$path = 'inc/languages/english';
$outputFile = 'mybb-english.json';

$strings = [];

$iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
);

foreach ($iterator as /** @var SplFileInfo $item */ $item) {
    $directory = substr($item->getPath(), strlen($path) + 1); // strip $path

    if ($directory === false) {
        $directory = '/';
    }

    if (preg_match('/\.lang\.php$/', $item->getFilename())) {
        $file = substr($item->getFilename(), 0, -9); // strip '.lang.php'

        require $item->getPathname();

        if (!isset($l)) {
            $l = [];
        }

        /** @var array<string, string> $l */

        $strings[$directory][$file] = $l;
        unset($l);
    }
}

file_put_contents(
    $outputFile,
    json_encode($strings, JSON_PRETTY_PRINT)
);


Also, a related tool: https://community.mybb.com/thread-227986.html

Thanks for the code, will be looking at it.

The tool I'm coding is a PHP translation tool where people will be able to see translation tips whilst translating (for languages supported by tools similar to Google Translate). Making it easier for people to translate instead of doing it from the files themselves. It will export to the correct files and structure itself so people won't have to think too much about it.

I was originally inspired by the excel project created in the thread you linked.
Hi, first of all, thank you for your contribution.

Regardless of it being useful in its current state at this current moment, I'm sure that any usable tool could be of use for future translators who might replace current ones at any given time.

Regards.