  You're browsing the documentation for an old version of SupportPal. Consider upgrading to the [latest version](https://docs.supportpal.com/current/Language+Packs). 

# Language Files

## Language Structure

Language strings are stored in files within the `/resources/lang` directory, with each subdirectory representing a language supported by the application. The name of the directory must be [Languages](Languages) in the operator panel; new languages will be disabled by default.

```

    /resources
        /lang
            /en
                core.php
            /es
                core.php

```

Each language files must return an array of language strings:

  **File Encoding**  
 Please ensure that all of your language files are saved with UTF-8 encoding otherwise the help desk may not function correctly. 

```

    <?php

    return [
        'product_name' => 'SupportPal'
    ];

```

## Basic Usage

Language strings can be accessed from any part of the application using `Lang::get()` function. If you need to access language files from within a template the syntax changes slightly to `Lang.get()`. For example, if you would like to access the `product_name` language string in the `core.php` file from within a PHP file:

```

    echo Lang::get('core.product_name');

```

Alternatively, from within a template file:

```

    {{ Lang.get('core.product_name') }}

```

### Variable Replacement

If you need to dynamically control words within language strings, this is possible using placeholders. All placeholders are prefixed by the `:` character.

```

    <?php

    return [
        'product_name' => 'SupportPal,
        'welcome'      => 'Welcome to :product_name'
    ];

```

We can then assign the placeholder value when accessing the language string:

```

    echo Lang::get('core.welcome', [ 'product_name' => Lang::get('core.product_name') ]); // Welcome to SupportPal

```

### Pluralisation

Often we make use of singular and plural forms of language strings. Pluralisation is possible via the pipe (`|`) character:

```

    <?php

    return [
        'product' => 'Product|Products'
    ];

```

Depending on whether we want to access the singular of plural form, the string can be accessed using the `Lang::choice()` function. The second parameter specifies which form we would like to retrieve:

```

    echo Lang::choice('core.product', 1); // Product
    echo Lang::choice('core.product', 2); // Products

```

## Contributing Languages

We are accepting user contributed languages to include as part of the main SupportPal releases in the near future. To contribute your own language files, please create a [pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) to the [language repository](https://github.com/supportpal/language-files), or alternatively [open a ticket](https://www.supportpal.com/support/en/tickets/create/step1) with us attached with the files and we will place them in the repository.

We really appreciate your contributions! Existing languages may also require updating to the latest version, for which we would appreciate contributions too.

Currently contributed languages:

- [Dutch (nl)](https://github.com/supportpal/language-files/tree/nl)
- [French (fr)](https://github.com/supportpal/language-files/tree/fr)
- [German (de)](https://github.com/supportpal/language-files/tree/de)
- [Persian (fa)](https://github.com/supportpal/language-files/tree/fa)
- [Spanish (es)](https://github.com/supportpal/language-files/tree/es)
- [Swedish (sv)](https://github.com/supportpal/language-files/tree/sv)