<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Craciun Ciprian</title>
    <description>The latest articles on DEV Community by Craciun Ciprian (@evalcraciun).</description>
    <link>https://dev.to/evalcraciun</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F182936%2F4097d7b3-f101-465e-8997-95627f99c5db.jpg</url>
      <title>DEV Community: Craciun Ciprian</title>
      <link>https://dev.to/evalcraciun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/evalcraciun"/>
    <language>en</language>
    <item>
      <title>Translate your next js project with next-translate</title>
      <dc:creator>Craciun Ciprian</dc:creator>
      <pubDate>Wed, 28 Jul 2021 18:31:08 +0000</pubDate>
      <link>https://dev.to/evalcraciun/translate-your-next-js-project-with-next-translate-2aa5</link>
      <guid>https://dev.to/evalcraciun/translate-your-next-js-project-with-next-translate-2aa5</guid>
      <description>&lt;p&gt;Do you have a &lt;strong&gt;next js&lt;/strong&gt; application and do you need multiple languages? Let's start to explain how to translate your &lt;strong&gt;next js&lt;/strong&gt; project with &lt;strong&gt;next-translate&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The first step is to decide which approach is the best for your &lt;strong&gt;next js&lt;/strong&gt; project. There are two main tasks you need to handle:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;manage JSON locales&lt;/li&gt;
&lt;li&gt;maintain separate URLs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Starting with version 10.0.0 Next js has built-in support for internationalized routing and he comes with two proposals:&lt;br&gt;Sub-path Routing and Domain Routing. If you like to read more about these two technics check the official &lt;a href="https://nextjs.org/docs/advanced-features/i18n-routing" rel="noreferrer noopener nofollow"&gt;link&lt;/a&gt;. In our tutorial, we will use sub-path routing, so let's start!&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with configurations
&lt;/h2&gt;

&lt;p&gt;First of all, we need a &lt;strong&gt;next-translate&lt;/strong&gt; package, install it with npm install next-translate, create an i18n JSON file in the root of the project and add your languages, check my example from the image, I will use stackblitz to create this tutorial and I will add the link of the project at the end of the article.&lt;/p&gt;

&lt;p&gt;I added few things in the &lt;strong&gt;i18n &lt;/strong&gt;file, &lt;strong&gt;locales &lt;/strong&gt;it's an array with the languages you want to have in your project, in my case "ro" it's for Romanian and "en" it's for English. I set up &lt;strong&gt;defaultLocale &lt;/strong&gt;to "ro" to be the default language for my project, you can set it to be your native language.&lt;/p&gt;

&lt;p&gt;As a small observation is to check which language is set on the browser, the project will be translated first time in the browser language.&lt;/p&gt;

&lt;p&gt;The last thing from the &lt;strong&gt;i18n &lt;/strong&gt;file is &lt;strong&gt;pages&lt;/strong&gt;, an array that contains the name of files with the translations for each page. I this tutorial I added just one file common to have the same examples.&lt;/p&gt;

&lt;p&gt;Create locales folder in the root of the project with languages you set up in the i18n file and also add &lt;strong&gt;next-translate&lt;/strong&gt; package to next.config.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const nextTranslate = require('next-translate');
module.exports = nextTranslate();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you already have configurations in your next.config.js file you need to wrap all the configurations into next-translate module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const nextTranslate = require("next-translate");
module.exports = nextTranslate({
  env: {
    REACT_APP_API: "http://localhost:3000",
  },
  eslint: {
    ignoreDuringBuilds: true,
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To summarize, add i18n.json file in the root of the project with your configurations and install next-translate package, create locales folder with languages and add common file name as JSON and import next-translate into next-config.js in order to load all configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Translate pages
&lt;/h2&gt;

&lt;p&gt;In our common.json file, we need to add some attributes, for example, if we decide to translate our title we should add it in both places locales/en and locales/ro:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// en
{
  "title": "Welcome to our translated page"
}

// ro
{
  "title": "Bine ati venit"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step we should do is to get our translated title on the Home page (any other component):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import useTranslation from 'next-translate/useTranslation';

//use into component
const { t, lang } = useTranslation('common');
const title = t('title');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create language switch component ( bonus )
&lt;/h2&gt;

&lt;p&gt;I've create also a component for switching our language, we set up the name of languages in common.json files, and then we can extract them in the component.&lt;/p&gt;

&lt;p&gt;I used &lt;strong&gt;react-bootstrap&lt;/strong&gt; to create the dropdown, you can use any other UI framework or you can build your own dropdown.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { Dropdown, DropdownButton } from 'react-bootstrap';
import i18nConfig from '../../i18n.json';
import useTranslation from 'next-translate/useTranslation';
import Link from 'next/link';

const SwitchLanguage = () =&amp;gt; {
  const { locales, defaultLocale } = i18nConfig;
  const { t, lang } = useTranslation('common');

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;DropdownButton id="dropdown-basic-button" title="Switch Lang"&amp;gt;
        {locales.map(lng =&amp;gt; {
          if (lng === lang) return null;
          return (
            &amp;lt;Dropdown.Item key={lng}&amp;gt;
              &amp;lt;Link href="/" locale={lng} key={lng}&amp;gt;
                {t(`common:language-name-${lng}`)}
              &amp;lt;/Link&amp;gt;
            &amp;lt;/Dropdown.Item&amp;gt;
          );
        })}
      &amp;lt;/DropdownButton&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default SwitchLanguage;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find the original article and stackblitz demo &lt;a href="https://stefaniq.com/translate-your-next-js-project-with-next-translate/"&gt;here&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to manage your package JSON file with npm</title>
      <dc:creator>Craciun Ciprian</dc:creator>
      <pubDate>Tue, 13 Jul 2021 11:01:33 +0000</pubDate>
      <link>https://dev.to/evalcraciun/how-to-manage-your-package-json-file-with-npm-4mce</link>
      <guid>https://dev.to/evalcraciun/how-to-manage-your-package-json-file-with-npm-4mce</guid>
      <description>&lt;p&gt;We are using every day &lt;strong&gt;npm package&lt;/strong&gt; and sometimes we forgot to check the latest updates from the package JSON file so how we update this file with &lt;strong&gt;npm&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;The best approach for a front-end project is always to have the latest packages updated. Why? You are up to date with the latest technologies and also you can prevent problems related to security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use npm outdated
&lt;/h2&gt;

&lt;p&gt;If we run npm outdated command in the root of the project, for a project with a package JSON file, we can see how many npm packages require updates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run npm update
&lt;/h2&gt;

&lt;p&gt;Running &lt;strong&gt;npm update&lt;/strong&gt; will auto-update packages without the need to update them manually. &lt;/p&gt;

&lt;p&gt;Before running &lt;strong&gt;npm update&lt;/strong&gt; if you have some packages that don't need updates or maybe it's a package with some deprecations, no longer maintained by the author, you can change the version of the package to be fixed like this: "next": "^10.2.3" → "next": "10.2.3".&lt;/p&gt;

&lt;p&gt;Removing the "^" from the package version, we set a fixed version and when we run &lt;strong&gt;npm update&lt;/strong&gt; that package will not be updated to the next version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scan your project for vulnerabilities with npm audit
&lt;/h2&gt;

&lt;p&gt;Yes, we can audit our packages running npm audit, this will tell you if you have any vulnerabilities and what to do to fix them.&lt;/p&gt;

&lt;p&gt;Read carefully all the pieces of information from the report, some suggestions may not be a fit for your project.&lt;/p&gt;

&lt;p&gt;The last command you should run after report review is &lt;strong&gt;npm audit fix&lt;/strong&gt;, this will automatically update all the broken packages. Other options for &lt;strong&gt;npm audit&lt;/strong&gt; can be found on the &lt;a href="https://docs.npmjs.com/cli/v7/commands/npm-audit" rel="noreferrer noopener"&gt;official docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;From my point of view, this would be a good behavior to have as a Developer, check your packages because when you code new features it's easy just to add packages without checking for vulnerabilities.&lt;/p&gt;

&lt;p&gt;If you like what I suggested here you can follow me on &lt;a href="https://twitter.com/StefanCraciun5" rel="noreferrer noopener"&gt;Twitter&lt;/a&gt; or subscribe to my &lt;a href="https://tinyletter.com/stefaniq1" rel="noreferrer noopener"&gt;newsletter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The original article can be found on my &lt;a href="https://stefaniq.com/how-to-manage-your-package-json-file-with-npm/"&gt;personal blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Generate meta tags in react js for sharing</title>
      <dc:creator>Craciun Ciprian</dc:creator>
      <pubDate>Fri, 05 Feb 2021 10:14:37 +0000</pubDate>
      <link>https://dev.to/evalcraciun/generate-meta-tags-in-react-js-for-sharing-3ld2</link>
      <guid>https://dev.to/evalcraciun/generate-meta-tags-in-react-js-for-sharing-3ld2</guid>
      <description>&lt;p&gt;If you are building websites using react js with create-react-app it's great but we have a problem with meta tags.&lt;/p&gt;

&lt;p&gt;Suppose you have a blog on your react js web application and you want to share your article to get more visibility, the problem is Facebook, LinkedIn and Twitter doesn't recognize your meta tags because of your index.html file from the build.&lt;/p&gt;

&lt;p&gt;In order to have a great preview when you share an article, Facebook and LinkedIn need to have in the header of the page open graph meta tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta property="og:title" content="" /&amp;gt;
&amp;lt;meta property="og:url" content="" /&amp;gt;
&amp;lt;meta property="og:type" content="article" /&amp;gt;
&amp;lt;meta property="og:description" content="" /&amp;gt;
&amp;lt;meta property="og:image" content="" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Twitter we need to have another set of meta tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta property="twitter:title" content="" /&amp;gt;
&amp;lt;meta property="twitter:description" content="" /&amp;gt;
&amp;lt;meta property="twitter:image" content="" /&amp;gt;
&amp;lt;meta property="twitter:card" content="" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the above meta tags are present in your article you can check how the preview share will look using the official debuggers: &lt;a href="https://developers.facebook.com/tools/debug/"&gt;Facebook debugger&lt;/a&gt;, &lt;a href="https://www.linkedin.com/post-inspector/"&gt;Linkedin debugger&lt;/a&gt;, and &lt;a href="https://developers.facebook.com/tools/debug/"&gt;Twitter debugger&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to fix meta tags in our react js app?
&lt;/h2&gt;

&lt;p&gt;The only good solution would be to serve those meta tags server-side. As the official documentation suggests you can place some placeholders in the index.html file and every time you change the page the server would fill those placeholders with the right words, as an example, meta tags should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
 &amp;lt;meta property="og:title" content="__OG_TITLE__" /&amp;gt;
 &amp;lt;meta property="og:description" content="__OG_DESCRIPTION__" /&amp;gt;
 &amp;lt;meta property="og:url" content="__OG_URL__" /&amp;gt;
 &amp;lt;meta property="og:image" content="__OG_IMAGE__" /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use an external library
&lt;/h2&gt;

&lt;p&gt;There is a lot of discussions about using &lt;a href="https://github.com/nfl/react-helmet"&gt;react-helmet&lt;/a&gt;, yes is very easy to use and to update your meta tags from a component instead of changing from the index.html file.&lt;/p&gt;

&lt;p&gt;Depends on the content of your website and what purpose should serve, in my case because I worked on a blog website the best solution was to serve those meta tags from the server.&lt;/p&gt;

&lt;p&gt;Don't forget to use those official tools from Facebook, LinkedIn, and Twitter they help a lot.&lt;/p&gt;

&lt;p&gt;If you like what I suggested here you can follow me on &lt;a href="https://twitter.com/StefanCraciun5"&gt;Twitter&lt;/a&gt; or subscribe to my &lt;a href="https://tinyletter.com/stefaniq1"&gt;newsletter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The original article can be found on my &lt;a href="https://stefaniq.com/generate-meta-tags-in-react-js-for-sharing/"&gt;blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>metatags</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Old website, new design</title>
      <dc:creator>Craciun Ciprian</dc:creator>
      <pubDate>Sat, 02 Jan 2021 13:31:25 +0000</pubDate>
      <link>https://dev.to/evalcraciun/old-website-new-design-n9e</link>
      <guid>https://dev.to/evalcraciun/old-website-new-design-n9e</guid>
      <description>&lt;p&gt;I'm using &lt;strong&gt;WordPress&lt;/strong&gt; for the website and I added this year(2021) a new design on it. Is still &lt;strong&gt;WordPress&lt;/strong&gt; a good choice in 2021 ? I would love to have some feedback about &lt;strong&gt;WordPress&lt;/strong&gt;, &lt;strong&gt;design&lt;/strong&gt; and the &lt;strong&gt;blog&lt;/strong&gt; part.&lt;/p&gt;

&lt;p&gt;Website: &lt;a href="https://stefaniq.com/"&gt;https://stefaniq.com/&lt;/a&gt;&lt;br&gt;
My twitter: &lt;a href="https://twitter.com/StefanCraciun5"&gt;https://twitter.com/StefanCraciun5&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>webdev</category>
      <category>website</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
