Language Frontend
A trait for handling language-related functionality in the frontend
This trait provides methods for managing language preferences and article redirection based on language settings.
Methods
change_lang()
Changes the language cookie based on user selection.
This method sets a cookie with the user’s selected language preference.
The cookie is set with the following properties:
- Name: ‘selected_lang’
- Expiration: 86500 seconds (approximately 24 hours)
- Path: ’/’
- Secure: TRUE
checkLanguageOfArticleOrRedirect()
Checks the language of an article and redirects if necessary.
This method compares the current language with the article’s language and performs redirections based on certain conditions.
- If there’s only one language, the method returns immediately.
- If no language cookie is set, it sets the cookie to the main language.
- The method performs various redirections based on the article’s language and the current language setting.
getOtherLanguageArticle()
Retrieves the article in the other language.
This method finds and returns the corresponding article in the other language.
Constants Used
The trait uses several constants that should be defined elsewhere in the application:
NUMBER_OF_LANGUAGES
MAIN_LANGUAGE
SECOND_LANGUAGE
Ensure these constants are properly defined before using this trait.
Dependencies
This trait depends on the following:
- CodeIgniter’s input library for cookie handling
- A model or service (referred to as
$this->fm
) for fetching article data
Make sure the required dependencies are properly initialized before using the methods in this trait.