Tag Archive for: Bash

Create a multilingual React website

First of all create a react app ready to go

create-react-app MY-WEBSITE

This will create a react app with everything configured.

npm start

Add i18next package

npm i -S i18next

This will let us do our website/app internationalization.

Set up your I18next file

Create a i18n.js file in the src folder with this code:

import i18n from 'i18next';

i18n
  .init({
    fallbackLng: 'en',
    lng: navigator.language.split('-')[0],
    debug: true,
    resources: {
      en: {
        translation: {
          "Hola": "Hello",
          "Adiós": "Bye"
        }
      }
    }
  });

export default i18n;

Finally, indicate which text you want to translate

Import your i18n.js and use its t function to indicate where it should be the internationalization.

import React, { Component } from 'react';
import logo from './logo.svg';
import i18n from './i18n';
import './App.css';

let t = i18n.t.bind(i18n);

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>{t("Hola")}</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default App;

 

Dealing with keystores and passwords when building for Android with Cordova

Which is the easiest way of builing apps in Android with Cordova?

Use a build.json file

{
     "android": {
         "release": {
             "keystore": "./your_keystore_file",
             "storePassword": "your_keystore_password",
             "alias": "your_alias_name",
             "password" : "your_alias_password"
         }
     }
 }

And type in your console: cordova build android –release

If you already have a keystore and don’t know what alias to use, run the command: keytool -list -v -keystore YOUR_KEYSTORE_FILE to see all the available aliases.

Keystore only has one password. You can change it using keytool: keytool -storepasswd -keystore MY_KEYSTORE

Note: I’m locating my build.json and keystore_file in my project’s root folder.

My Bash Prompt customization

14:34 gengns@mycomputer  Desktop$ ▮

Open a console in your HOME folder and type vim .bashrc, then copy the next line at the end of the file:

PS1='\[\e[30;47m\]\A \u@\h \W\[\e[0m\]$ '
  • \[\e[30;47m\] # 30 is black foreground color and 47 is light grey background
  • \A # hour in hh:mm format
  • \u # user name
  • \h # host name
  • \W  # working folder name
  • \[\e[0m\] # reset

More info: customization and colors in Bash

Would you like to start with web development?

UPDATED: 2022-05-06

If you don’t know anything about programming but you would like to start creating your own webs, desktop or mobile apps from scratch, I’m here to help you out ^^

Break the ice with a short fun history about JavaScript and the Web

  1. From undefined to something.js

Here we go, our first real code contact! You can start doing these fantastic courses from CodeAcademy (guided step by step, interactive and very basic)

  1. Introduction to HTML
  2. Introduction to CSS
  3. Introduction to JavaScript (and intermediate)

Follow with these complete courses from W3CSchools (a wider guide with many examples)

  1. HTML – The language for building webs
  2. CSS – The language for styling webs
  3. JavaScript – The language for programming webs

Don’t worry if some concept are repeated, you need to consolidate, humans learn buy doing.

Another really good option is Mozilla Developer Network (shared knowledge for the Open Web) and all courses about Web Technologies where you can find a wonderful documentation, tutorials and tools. Everything very well structured and in many different languages with the chance to dive deeper into Web Technologies.

After doing CodeAcademy, W3CSchools courses and having taken a glance to MDN I would recommend you to watch this YouTube tutorial: Understanding the Weird Parts of JavaScript. It’s also really basic but it explains some aspects under the hood of JS. This guy made a really good presentation, one of the best videos about JS I’ve ever seen. You can complete his course on Udemy.

After consolidating a good base:

  1. Functional Programming with JavaScript (mandatory)
  2. Understanding the even loop (mandatory)
  3. CSS Grid
  4. Svelte
  5. Some of my tricks

Things are as easy as you want them, the knowledge should be open and free for everyone. There are many genius out there and most of them cannot afford their studies, even if they are public. Do not keep your knowledge for you, spread it out together with your ideas to build a better world 🙂

How to make a mobile app?

cordova-logo

In this tutorial I’m going to explain you step by step how I make phone apps using Cordova (Phonegap/Ionic) and Ubuntu.

1) Install Cordova

For those who don’t know anything about Cordova, it is an opensource platform for building multiple platforms applications using HTML, CSS and JavaScript. The main different between Cordova and Phonegap is that the second one gets the Cordova code and redistributes with some Adobe rights, now it’s free but maybe tomorrow who knows, my recommendation is to use Cordova that apart of this is always more updated!

So, first step you have to install Cordova, open a shell in Ubuntu and type:

$ sudo npm install -g cordova

Any problems? See the Cordova documentation.

2) Install Platform

After that you need to install a platform, in this example we are going to develop an Android app so you have to install the Android SDK.

I recommend you to install Android Studio that brings you the SDK and many extra tools in an user friendly access. Get Android Studio.

Once you download it and unzipped it, you have to run it the first time to install everything. If you set android-studio in your home folder, it will create an Android folder with the SDK.

3) Add Android SDK to your “PATH”

Make Android SDK accessible in your environment (system)

Open a shell and type:

$ nano ~/.bashrc

Then you need to add to your “PATH” variable where your SDK and Gradle are.

export ANDROID_SDK_ROOT=~/Android/Sdk
export PATH=${PATH}:~/Android/Sdk/tools:~/Android/Sdk/platform-tools:~/android-studio/gradle/gradle-5.1.1/bin

After that, reload bashrc, if not it will not have any effect.

$ source ~/.bashrc

Note: you need to set your own path and names for the Android SDK, I used my “home” folder and default Android Studio’s folders.

4) Install Text Editor / IDE

Use the one you feel more confortable, my favorites are: Atom and VSCodium.

5) Create your App

$ cordova create myApp
$ cd myApp
$ cordova platform add android
$ cordova run --debug --device

Now you can start programming! HTML, CSS and JavaScript files are in the “www” folder.

Remember you need to activate developer options in your Android phone.

If you have any access problem (EACCES)  to your android-studio folder.

$ chmod 777 -R ~/android-studio/

Enjoy 🙂

Here if you want you can download my Cordova logo and use it for free: Cordova logo