Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Vanilla 2.6 is here! It includes security fixes and requires PHP 7.0. We have therefore ALSO released Vanilla 2.5.2 with security patches if you are still on PHP 5.6 to give you additional time to upgrade.

How to quickly grab the latest localizations

JasonBarnabeJasonBarnabe Cynical Salamander ✭✭

I have a multilingual forum that currently supports 15 languages and will probably support more in the future. Now that the locales are being regularly updated, I was wondering if there was an easy way for me to download the updates. On the addons site, the file names seem to be versionned, so I don't think I can make a script to wget and unzip them. On Transifex, it looks like they require additional processing before being used, as there are files in the addons download that aren't present in Transifex.

Any ideas on the best way to do this?

Comments

  • BleistivtBleistivt MVP
    edited November 2014

    http://vanillaforums.org/addon.json/vf_zh_tw-locale

    The "File" field shows the actual filename of the latest revision:

    {
     ...
     "AddonVersionID":3252,
     "File":"~cf\/addons\/8LQ2S09WFWMV.zip",
     "Version":"2014.11.03p1348",
     ...
    }
    

    So you can directly download it from
    https://us.v-cdn.net/5018160/uploads/addons/8LQ2S09WFWMV.zip

    But yes, a little bit of scripting would be required.

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

    JasonBarnabehgtonight
  • hgtonighthgtonight ∞ · New Moderator

    @Bleistivt‌ Couldn't you just use the 'Url' field a few lines down? ;)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    BleistivtShadowdare
  • BleistivtBleistivt MVP
    edited November 2014

    Yes, we learn

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

    hgtonightR_J
  • JasonBarnabeJasonBarnabe Cynical Salamander ✭✭

    Great, thanks. I'll see if I can write a shell script for this and I'll post it here when it's done.

    BleistivthgtonightShadowdare
  • JasonBarnabeJasonBarnabe Cynical Salamander ✭✭
    edited November 2014
    <?php
    
    // Path to your Vanilla install.
    $vanilla_path = '/www/vanilla/';
    
    // Locale codes to download - should match Vanilla's standards, for example "fr" and "pt_BR".
    $locale_codes = ['bg', 'de', 'es', 'fr', 'id', 'it', 'ja', 'nl', 'pl', 'pt_BR', 'ru', 'vi', 'zh', 'zh_TW'];
    
    foreach ($locale_codes as $locale_code) {
    
      $url="http://vanillaforums.org/addon.json/vf_".$locale_code."-locale";
    
      $json = file_get_contents($url);
      $data = json_decode($json, TRUE);
    
      $locale_url = $data['Url'];
      $zip_path = $vanilla_path.'locales/'.$locale_code.'.zip';
      $dir_path = $vanilla_path.'locales/';
    
      echo "Downloading '".$locale_url."' to '".$zip_path."'.\n";
    
      if (!function_exists(curl_init)) {
        echo "Could not call curl_init. Make sure the curl extension is installed - see http://php.net/manual/en/curl.setup.php.\n";
        exit;
      }
    
      $ch = curl_init($locale_url);
      $fp = fopen($zip_path, "w");
    
      curl_setopt($ch, CURLOPT_FILE, $fp);
      curl_setopt($ch, CURLOPT_HEADER, 0);
    
      curl_exec($ch);
      curl_close($ch);
    
      if (!class_exists(ZipArchive)) {
        echo "Could not make ZipArchive object. Make sure the zip extension is installed - run \"pecl install zip\".\n";
        exit;
      }
      $zip = new ZipArchive();
      $zip->open($zip_path);
      echo "Extracting '".$zip_path."' to '".$dir_path."'.\n";
      $zip->extractTo($dir_path);
      $zip->close();  
      echo "Deleting '".$zip_path."'.\n";
      unlink($zip_path);
    }
    
    hgtonightR_J
  • JasonBarnabeJasonBarnabe Cynical Salamander ✭✭

    Updated code to not use fopen:

    <?php
    
    // Path to your Vanilla install.
    $vanilla_path = '/www/vanilla/';
    
    // Locale codes to download - should match Vanilla's standards, for example "fr" and "pt_BR".
    $locale_codes = ['bg', 'de', 'es', 'fr', 'id', 'it', 'ja', 'nl', 'pl', 'pt_BR', 'ru', 'vi', 'zh', 'zh_TW'];
    
    foreach ($locale_codes as $locale_code) {
    
      $locale_info_url="http://vanillaforums.org/addon.json/vf_".$locale_code."-locale";
    
      if (!function_exists(curl_init)) {
        echo "Could not call curl_init. Make sure the curl extension is installed - see http://php.net/manual/en/curl.setup.php.\n";
        exit;
      }
    
      echo "Downloading info for locale '".$locale_code."' from '".$locale_info_url."'.\n";
    
      $ch = curl_init($locale_info_url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      $json = curl_exec($ch);
      curl_close($ch);
    
      $data = json_decode($json, TRUE);
    
      $locale_url = $data['Url'];
      $zip_path = $vanilla_path.'locales/'.$locale_code.'.zip';
      $dir_path = $vanilla_path.'locales/';
    
      echo "Downloading '".$locale_url."' to '".$zip_path."'.\n";
    
      $ch = curl_init($locale_url);
      $fp = fopen($zip_path, "w");
      curl_setopt($ch, CURLOPT_FILE, $fp);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_exec($ch);
      curl_close($ch);
    
      if (!class_exists(ZipArchive)) {
        echo "Could not make ZipArchive object. Make sure the zip extension is installed - run \"pecl install zip\".\n";
        exit;
      }
      $zip = new ZipArchive();
      $zip->open($zip_path);
      echo "Extracting '".$zip_path."' to '".$dir_path."'.\n";
      $zip->extractTo($dir_path);
      $zip->close();  
      echo "Deleting '".$zip_path."'.\n";
      unlink($zip_path);
    }
    
    R_J
  • LincLinc Director of Development Detroit Vanilla Staff
    edited November 2014

    Symlink the locales repo on your web server. Then all you need to do is git pull.

  • JasonBarnabeJasonBarnabe Cynical Salamander ✭✭
    edited November 2014

    That'd work if the repo was up-to-date. I'm pointing my localizers to Vanilla's Transifex to help out, and I'd like to be at most a day or two behind.

    Bleistivt
Sign In or Register to comment.