Welcome to Geeklog, Anonymous Wednesday, December 17 2025 @ 04:12 am EST
Geeklog Forums
roposal to update COM_getLanguageId() for simpler and clearer language detection
Status: offline
ivywe
Forum User
Newbie
Registered: 08/14/25
Posts: 12
Hi all,
The purpose of this change:
Currently, Geeklog’s language detection is quite complex and can display different content for the same URL depending on various factors. However, Google’s crawler guidelines recommend a clear “one URL, one piece of content” approach.
For this reason, I propose modifying the core lib-common.php to make the behavior more predictable and crawler-friendly.
I have implemented this change by updating the COM_getLanguageId() function.
Below is the key part of the change:
// Get last segment of URL path
$segments = explode('/', trim($uri, '/'));
$last_segment = end($segments);
// If last segment is "code", use the previous segment
if ($last_segment === 'code' && count($segments) > 1) {
$last_segment = prev($segments);
}
// Extract text after last "_" as language ID
$pos = MBYTE_strrpos($last_segment, '_');
if ($pos > 0) {
$candidate = MBYTE_substr($last_segment, $pos + 1);
if (array_key_exists($candidate, $_CONF['language_files'])) {
$lang_id = $candidate;
}
}
This ensures:
/page_en → en
/page_en/code → en
If no match, defaults to the first key in $_CONF['language_files'].
You can see the full code in my repository:
https://github.com/ivywe/Geeklog-2-2-2-jp/blob/main/public_html/lib-common.php
/**
* COM_getLanguageId
*
* Retrieves the language ID from the last segment of the URL (supports "/code" suffix as well).
* If not found, returns the first key in $_CONF['language_files'].
*
* This function overrides Geeklog core's COM_getLanguageId for custom URL handling.
*
* @param string $language Ignored (kept for compatibility)
* @return string Language ID
*/
function COM_getLanguageId($language = '')
{
global $_CONF;
$lang_id = '';
// Get the path part of the URL (remove query string)
$uri = $_SERVER['REQUEST_URI'];
$uri = parse_url($uri, PHP_URL_PATH);
// Get the last segment of the path
$segments = explode('/', trim($uri, '/'));
$last_segment = end($segments);
// If the last segment is "code", use the previous segment instead
if ($last_segment === 'code' && count($segments) > 1) {
$last_segment = prev($segments);
}
// If the segment contains "_", extract the part after the last "_"
$pos = MBYTE_strrpos($last_segment, '_');
if ($pos > 0 && ($pos + 1) < MBYTE_strlen($last_segment)) {
$candidate = MBYTE_substr($last_segment, $pos + 1);
// Check if the candidate exists in $_CONF['language_files']
if (isset($_CONF['language_files']) && array_key_exists($candidate, $_CONF['language_files'])) {
$lang_id = $candidate;
} else {
COM_errorLog('Language "' . $candidate . '" not found in $_CONF[\'language_files\'] array!');
}
}
// If no valid language ID found, use the first key in $_CONF['language_files']
if ($lang_id === '' && isset($_CONF['language_files']) && is_array($_CONF['language_files']) && !empty($_CONF['language_files'])) {
$keys = array_keys($_CONF['language_files']);
$lang_id = reset($keys);
}
return $lang_id;
}
Please review and consider this update.
The purpose of this change:
Currently, Geeklog’s language detection is quite complex and can display different content for the same URL depending on various factors. However, Google’s crawler guidelines recommend a clear “one URL, one piece of content” approach.
For this reason, I propose modifying the core lib-common.php to make the behavior more predictable and crawler-friendly.
I have implemented this change by updating the COM_getLanguageId() function.
Below is the key part of the change:
Text Formatted Code
// Get last segment of URL path
$segments = explode('/', trim($uri, '/'));
$last_segment = end($segments);
// If last segment is "code", use the previous segment
if ($last_segment === 'code' && count($segments) > 1) {
$last_segment = prev($segments);
}
// Extract text after last "_" as language ID
$pos = MBYTE_strrpos($last_segment, '_');
if ($pos > 0) {
$candidate = MBYTE_substr($last_segment, $pos + 1);
if (array_key_exists($candidate, $_CONF['language_files'])) {
$lang_id = $candidate;
}
}
This ensures:
/page_en → en
/page_en/code → en
If no match, defaults to the first key in $_CONF['language_files'].
You can see the full code in my repository:
https://github.com/ivywe/Geeklog-2-2-2-jp/blob/main/public_html/lib-common.php
Text Formatted Code
/**
* COM_getLanguageId
*
* Retrieves the language ID from the last segment of the URL (supports "/code" suffix as well).
* If not found, returns the first key in $_CONF['language_files'].
*
* This function overrides Geeklog core's COM_getLanguageId for custom URL handling.
*
* @param string $language Ignored (kept for compatibility)
* @return string Language ID
*/
function COM_getLanguageId($language = '')
{
global $_CONF;
$lang_id = '';
// Get the path part of the URL (remove query string)
$uri = $_SERVER['REQUEST_URI'];
$uri = parse_url($uri, PHP_URL_PATH);
// Get the last segment of the path
$segments = explode('/', trim($uri, '/'));
$last_segment = end($segments);
// If the last segment is "code", use the previous segment instead
if ($last_segment === 'code' && count($segments) > 1) {
$last_segment = prev($segments);
}
// If the segment contains "_", extract the part after the last "_"
$pos = MBYTE_strrpos($last_segment, '_');
if ($pos > 0 && ($pos + 1) < MBYTE_strlen($last_segment)) {
$candidate = MBYTE_substr($last_segment, $pos + 1);
// Check if the candidate exists in $_CONF['language_files']
if (isset($_CONF['language_files']) && array_key_exists($candidate, $_CONF['language_files'])) {
$lang_id = $candidate;
} else {
COM_errorLog('Language "' . $candidate . '" not found in $_CONF[\'language_files\'] array!');
}
}
// If no valid language ID found, use the first key in $_CONF['language_files']
if ($lang_id === '' && isset($_CONF['language_files']) && is_array($_CONF['language_files']) && !empty($_CONF['language_files'])) {
$keys = array_keys($_CONF['language_files']);
$lang_id = reset($keys);
}
return $lang_id;
}
Please review and consider this update.
12
19
Quote
Status: offline
ivywe
Forum User
Newbie
Registered: 08/14/25
Posts: 12
We are currently managing our site with Geeklog’s multilingual specifications.
Instead of relying only on the built-in language detection, we have configured Apache rewrite rules to redirect based on the browser’s language setting:
.htaccess:
RewriteCond %{HTTP:Accept-Language} ^ja [NC]
# Redirect to home_ja for Japanese environment
RewriteRule ^$ /index.php/topic/home_ja [L]
# Redirect to home_en for non-Japanese environments
RewriteRule ^$ /index.php/topic/home_en [L]
As part of our multilingual setup, we operate with rules such as:
/index.php/topic/home_ja
/index.php/topic/home_en
In this way, we create separate topics for each language and manage them independently.
I just wanted to share this approach, in case it’s useful for others who are setting up multilingual sites with Geeklog.
Best regards,
Ivy
Instead of relying only on the built-in language detection, we have configured Apache rewrite rules to redirect based on the browser’s language setting:
.htaccess:
Text Formatted Code
# Check the browser language settingRewriteCond %{HTTP:Accept-Language} ^ja [NC]
# Redirect to home_ja for Japanese environment
RewriteRule ^$ /index.php/topic/home_ja [L]
# Redirect to home_en for non-Japanese environments
RewriteRule ^$ /index.php/topic/home_en [L]
As part of our multilingual setup, we operate with rules such as:
/index.php/topic/home_ja
/index.php/topic/home_en
In this way, we create separate topics for each language and manage them independently.
I just wanted to share this approach, in case it’s useful for others who are setting up multilingual sites with Geeklog.
Best regards,
Ivy
15
16
Quote
All times are EST. The time is now 04:12 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content