Language Packs: Upgrading

Previous Section: Dynamic Content


One may wish to update the language pack at some point in the future. This can be done by making use of the simple upgrade system that can run targeted code when the currently installed version is below the new version.

The upgrade code should be placed in the activate function, as this is run again on each upgrade. The installedVersion helper gives you the version installed that is currently stored in the database, and this can be compared against a static version number to allow you to run code specific to the version the feature/change was added in. The installedVersion helper will give a value of null on the first activation of the language pack, or the previously installed version if the plugin was language pack and then deactivated at least once.

Below is an example of adding another dynamic content translation in version 1.1 of the language pack.


    /**
     * Languages can run an installation routine when they are activated. This will typically include adding default
     * values, initialising database tables and so on.
     *
     * @return boolean
     */
    public function activate()
    {
        // First install only.
        if ($this->installedVersion() === null) {
            // Translate 'Open' status.
            \DB::table('ticket_status_translation')->insertOrIgnore([
                'status_id' => 1,
                'name'      => 'Abierto',
                'locale'    => 'es',
            ]);
        }

        // Added in version 1.1.
        if ($this->installedVersion() === null || version_compare('1.1', $this->installedVersion()) === 1) {
            // Translate 'Closed' status.
            \DB::table('ticket_status_translation')->insertOrIgnore([
                'status_id' => 2,
                'name'      => 'Cerrado',
                'locale'    => 'es',
            ]);
        }

        return true;
    }

Users of the language pack must upload the new version to their /addons/Languages folder, visit the Languages page (Settings -> General -> Languages) in the operator panel and click the Upgrade & Reactivate link for it to run the upgrade code.

Language Pack Upgrade Pending


Next Section: Available Language Packs