Page 1 of 1

Tools > Define Languages

Posted: Tue Nov 16, 2021 1:38 pm
by heatherbell
admin/define_language.php
We use this page a lot and spend a lot of time looking for the relevant file in the long list which, for us, is ordered in an unhelpful way.
Is it possible to order the list A-Z by filename without changing the core file?
Maybe it's just us that has this issue with the list?
If not, is it something that would help other users if changed in core?
TYIA

Re: Tools > Define Languages

Posted: Tue Nov 16, 2021 2:36 pm
by ecartz
heatherbell wrote: Tue Nov 16, 2021 1:38 pm Is it possible to order the list A-Z by filename without changing the core file?
Not at the moment. It would be possible to make it changeable without modifying core. I can look into that later. It will probably be a few versions, at least 1.0.8.10.

New file admin/includes/classes/override/translation_tree.php

Code: Select all

class translation_tree {

  const EXCLUDES = ['.', '..', '.DS_Store', 'Thumbs.db'];

  protected static function _read($directory, &$files) {
    $directory = rtrim($directory, '/') . '/';

    if ($handle = opendir($directory)) {
      while (false !== ($filename = readdir($handle))) {
        if (in_array($filename, static::EXCLUDES)) {
          continue;
        }

        $path = $directory . $filename;
        $file = [
          'name' => $path,
          'is_dir' => is_dir($path),
          'writable' => Path::is_writable($path),
          'size' => filesize($path),
          'last_modified' => strftime(DATE_TIME_FORMAT, filemtime($path)),
        ];

        $files[] = $file;
        if ($file['is_dir']) {
          static::_read($path, $files);
        }
      }
    }
  }

  public static function read($path) {
    $files = [];
    static::_read($path, $files);

    usort($files, function ($a, $b) {
      return strcmp(basename($a['name']), basename($b['name']));
    });

    return $files;
  }

}
And then change line 187 to

Code: Select all

    foreach (translation_tree::read(DIR_FS_CATALOG_LANGUAGES . $_GET['lngdir']) as $file) {
Then when I next modify it, I'll include the latter change in core and things should just continue to work.

Re: Tools > Define Languages

Posted: Tue Nov 16, 2021 3:17 pm
by heatherbell
@ecartz
On 1.0.8.7 that gives:
unexpected ',', expecting ')' in

Code: Select all

  $path = rtrim($directory,, '/') . '/';
I guess there's one too many commas there so removed one but that then gives:
unexpected 'public' (T_PUBLIC) in

Code: Select all

public static function read($path) {
I guessed there was a missing } before that line so added it but that then gives numerous warnings like:
filesize(): stat failed for /includes/languages/englishcontact_us.php
filemtime(): stat failed for /includes/languages/englishcontact_us.php

I notice a missing / in those warnings
and the list shows filenames with first letter missing like e.g. ccount.php
and only lists language files for pages, does not list any of the module language files
I'm stuck now :(

Re: Tools > Define Languages

Posted: Tue Nov 16, 2021 6:19 pm
by ecartz
I updated the previous post to hopefully fix the syntax errors. I think that the last set of problems was from assigning to the wrong variable after the rtrim.

Re: Tools > Define Languages

Posted: Wed Nov 17, 2021 8:01 am
by heatherbell
ecartz wrote: Tue Nov 16, 2021 6:19 pm I updated the previous post to hopefully fix the syntax errors. I think that the last set of problems was from assigning to the wrong variable after the rtrim.
Many thanks - all warnings now gone but the sorting, although improved, is still not entirely A-Z as hoped.
Screenshot 2021-11-17 075726.png

Re: Tools > Define Languages

Posted: Wed Nov 17, 2021 8:35 am
by ecartz
So english.php is first, because it's hardcoded that way. That might be difficult to change. It would probably be easier just to remember where it is, since it would always be first. If this really bothers you, we can talk about it again when I next modify that file.

MATC.php is before about_us.php because capital letters sort before lowercase letters. If that bothers you, you could change that by changing strcmp to strcasecmp in the new file.

That's the only two things that look out of order to me. And like I said, both are in a predictable order.

Re: Tools > Define Languages

Posted: Wed Nov 17, 2021 8:52 am
by heatherbell
ecartz wrote: Wed Nov 17, 2021 8:35 am both are in a predictable order.
Many thanks, I just did not understand the anomalies, as long as it is sorting as expected.
The change will make scanning, by eye, a list of about 250 items easier.
Of course, there is the option of app.php/addons/free_addon/language_search_edit/, thanks to zipurman.