I think I found it:
get_translate_post_link
No, I was wrong, this is for new page in admin part
I found the solution, but it was more troublesome than expected. I have only two languages on my page, so example is simplified in regards to general solution.
If you would accept my contribution, I will write and expose functions for developers to do exactly that simpler – return url of the page when language is given and return language of current page
Here is my code:
<?php
function nLanguage_menuswitch_output() {
// 1- english, 2-croatian
$language_to_switch_to_id =
(nLingual\Registry::current_language()->id == 1) ? 2 : 1;
// get language object
$language_to_switch_to = nLingual\Registry::get_language($language_to_switch_to_id);
// get target url
$target_url = nLingual\Rewriter::localize_here($language_to_switch_to);
// output language menu
if ($language_to_switch_to_id == 1) :
?>
HRVATSKI / <a href="<?= $target_url ?>" aria-label="Change language to english">ENGLESKI</a>
<?php
else :
?>
<a href="<?= $target_url ?>" aria-label="Promijeni jezik u hrvatski">HRVATSKI</a> / ENGLESKI
<?php
endif;
}
Hi,
The plugin offers a way to add these links via the nav menu (a Language Links box will appear in the left column of the menu editor), however there’s not much of a built-in utility for printing a language nav outside of the template, since I didn’t want to lock-in the markup (though I could write something with config options for it).
In most cases on my projects, I write something like this in the header template.
<nav class="language-nav" role="Language">
<?php foreach ( nLingual\Registry::languages() as $i => $language ) : ?>
<?php echo $i ? '/' : ''; ?>
<a rel="alternate"
href="<?= nLingual\Rewriter::localize_here( $language ) ?>"
hreflang="<?= $language->locale_name ?>"
class="<?php echo nLingual\Registry::is_language_current( $language ) ? 'is-current' : ''; ?>"
><?= $language->short_name ?></a>
<?php endforeach; ?>
</nav>
That will print a <nav> element with an >a< link for each language the site supports, flaging the current one with the is-current class. The aria-label might be tricky to implement (maybe a sprintf() call using a localized string), but otherwise that should do the job.