English version is launched!

2 Jul 2020

Hello! Today I'm finally completed work on english version of my blog.

I had this idea for a long time. Anyway, english is mainly used in programming. Most part of my carrier I'm working for foreign clients. And it's not really comfortable to share my russian blog with foreign colleagues.

At the same time, I initially decided to create my blog on russian. All previous posts written on russian language. Finally, my mother tongue is very important for me. Then I decided to have 2 versions of website - russian and english version. It would make creation of new posts harder and slower. Anyway, I think it would be best approach.

There were different options how to split english and russian versions. It might be different domains, subdomain for english version, url prefix or, probably, some other options. I canceled idea with different domains, because current domain in .me zone is quite universal and can be used for both languages. I skipped subdoamin option, because then urls for english version would be quite ugly. Beside this, there would be 2 different websites, that might be bad for SEO.

Finally, I decided to use url prefix. Then /en/ would be added to the start of all urls for english version. If there is no prefix, then show russian version. Website works on Symfony, so such changes in routing was quite easy to do.

Firstly I replaced yaml routing to annotations. Then added such annotations for each action:

/**
 * @Route("/en/", name="en_index", locale="en")
 * @Route("/", name="index", locale="ru")
 */

/**
 * @Route("/en/post/{url}", name="en_post", locale="en")
 * @Route("/post/{url}", name="post", locale="ru")
 */

Then I used locale in code for language related logic.

$post = $this->postRepository->findByUrl($url, $request->getLocale());

I created separate russian and english fields for each entity. For example, I replaced title field to russian_title and english_title. Then added locale check to title getter.

I also created src/Helper/LocaleHelper.php, for additional code that works with locales. Then added some methods to src/Twig/AppExtension.php for usage in templates.

public function getFunctions()
{
    return [
        new TwigFunction('isLocaleRu', [$this, 'isLocaleRu']),
        new TwigFunction('getLocalePrefix', [$this, 'getLocalePrefix']),
        new TwigFunction('getLanguageIcon', [$this, 'getLanguageIcon']),
        new TwigFunction('getForeignLink', [$this, 'getForeignLink']),
    ];
}

Added header button for switch to another language to the header. Looks like that:

I spent a lot of time and efforts to translate all interface elements and content to english. I realized, that chatting and blogging is not the same things. Not sure, that I translated everything good. Probably I need to improve my writing skills.

Now I also need to write new posts on both languages, that would take additional time and efforts. I skipped translation of all old russian posts, because it would take a huge amount of time. I'm also not sure, that it really needed. Recent posts were already create on both languages.

English version launch took a lot of time and efforts for me. There was also a lot of work on other projects. Finally, I completed localization, then I'm going to do some refactoring and write more new posts.

That's all for today. Thank you for your attention!