Skip to content

Commit

Permalink
Use i18next json files for the moment
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasile Boris committed Mar 24, 2019
1 parent 285abd4 commit 5f88020
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .expo/packager-info.json
Expand Up @@ -2,9 +2,9 @@
"devToolsPort": 19002,
"expoServerPort": 19000,
"packagerPort": 19001,
"packagerPid": 18635,
"packagerPid": 4125,
"expoServerNgrokUrl": "https://sa-imr.anonymous.myreads.exp.direct",
"packagerNgrokUrl": "https://packager.sa-imr.anonymous.myreads.exp.direct",
"ngrokPid": 18736,
"ngrokPid": 4404,
"webpackServerPort": null
}
38 changes: 9 additions & 29 deletions App.js
@@ -1,8 +1,5 @@
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import i18next from 'i18next';
import Fetch from 'i18next-fetch-backend';
import PROP from '/utils/PROP';
import { StyleSheet, Text, View } from 'react-native';
import localizer from '/utils/Localizer';
import { fetchBooks } from '/api/BookApi';

Expand Down Expand Up @@ -31,31 +28,14 @@ export default class App extends React.Component {
}

componentDidMount() {
i18next
.use(Fetch)
.init({
backend: {
loadPath: lng => {
const suffix = 'en' !== lng ? `_${lng}` : '';
return `http://192.168.0.87:81/translations/Messages${suffix}.properties`
},
parse: data => PROP.parse(data)
},
lng: "en",
fallbackLng: "en",
interpolation: {
prefix: "{",
suffix: "}"
},
debug: true
}, () => {
fetchBooks().then((response) => {
this.setState({
isI18nInitialized: true,
books: response.data
})
});
localizer.init(() => {
fetchBooks().then((response) => {
this.setState({
isI18nInitialized: true,
books: response.data
})
});
});
}
}

Expand All @@ -66,4 +46,4 @@ const styles = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
},
});
});
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -10,7 +10,6 @@
"axios": "^0.18.0",
"expo": "^32.0.0",
"i18next": "^15.0.7",
"i18next-fetch-backend": "^2.2.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"
},
Expand Down
48 changes: 48 additions & 0 deletions translations/Messages.json
@@ -0,0 +1,48 @@
{
"app-title": "My Reads",
"add-button": "Add",
"edit-button": "Edit",
"update-button": "Update",
"delete-button": "Delete",
"cancel-button": "Cancel",
"clear-button": "Clear",
"read-button": "Read",
"books-search-text": "Search by Title / Author",
"book-add-button": "Add book",
"book-isbn10-text": "ISBN 10",
"book-isbn13-text": "ISBN 13",
"book-title-text": "Title",
"book-authors-text": "Authors",
"book-image-text": "Image url",
"book-pages-text": "Number of pages",
"book-by-label": "By",
"book-pages-label": "pages",
"book-no-image-available": "No image available",
"validation-value-is-required": "{0} is required",
"validation-value-is-positive-number": "{0} must be at least 1",
"validation-value-is-date": "{0} must be a date in the format yyyy-mm-dd",
"books-search-error": "Books cannot be searched. Please try again!",
"book-isbn-already-exists-error": "Book cannot be saved. ISBN is already used!",
"book-save-error": "Book cannot be saved. Please try again!",
"book-not-found-error": "Book was not found. Please try again!",
"book-retrieve-error": "Book cannot be retrieved. Please try again!",
"book-has-reading-session-error": "Book cannot be deleted. It has a current reading session!",
"book-delete-error": "Book cannot be deleted. Please try again!",
"date-reading-session-date-text": "Date",
"date-reading-session-last-read-page-text": "Last read page",
"date-reading-session-bookmark-text": "Bookmark",
"date-reading-session-last-read-page-label": "{0} pages read",
"date-reading-session-bookmark-label": "Continue with",
"reading-session-progress-status-label": "Read up to",
"reading-session-progress-average-pages-label": "pages / day",
"reading-session-progress-estimated-pages-left-label": "remaining pages",
"reading-session-progress-estimated-read-days-left-label": "sessions",
"reading-session-progress-estimated-days-left-label": "days",
"reading-session-progress-estimated-finish-date-label": "Complete by",
"reading-session-progress-deadline-label": "Need by",
"current-reading-session-not-found-error": "Current reading session was not found. Please try again!",
"current-reading-session-retrieve-error": "Error on retrieve reading session. Please try again!",
"date-reading-session-already-exists-error": "Reading session cannot be saved. The same date is already used!",
"date-reading-session-save-error": "Reading session cannot be saved. Please try again!",
"date-reading-session-delete-error": "Reading session cannot be deleted. Please try again!"
}
22 changes: 20 additions & 2 deletions utils/Localizer.js
@@ -1,13 +1,31 @@
import i18n from 'i18next';
import i18next from 'i18next';
import messages from "/translations/Messages";

const Localizer = {

init: function(callback) {
i18next.init({
lng: "en",
fallbackLng: "en",
interpolation: {
prefix: "{",
suffix: "}"
},
resources: {
en: {
translation: messages
}
},
debug: true
}, () => callback());
},

localize: function (key, ...args) {
const values = args.reduce((values, value, idx) => ({
...values,
[idx]: value
}) , {});
return i18n.t(key, values);
return i18next.t(key, values);
}

};
Expand Down
15 changes: 0 additions & 15 deletions utils/PROP.js

This file was deleted.

5 changes: 0 additions & 5 deletions yarn.lock
Expand Up @@ -3066,11 +3066,6 @@ http-errors@~1.6.2:
setprototypeof "1.1.0"
statuses ">= 1.4.0 < 2"

i18next-fetch-backend@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/i18next-fetch-backend/-/i18next-fetch-backend-2.2.0.tgz#39ff6578596e0122e80692e04d7897ee373607d6"
integrity sha512-HodOCr4fezjMgJwWnOR/JUotdbM1onXdnB6Y+XDgDpXX58SkZXcyz6VmmUGc/8XMxFzq3162Qs2vO+SlO4TCFw==

i18next@^15.0.7:
version "15.0.7"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-15.0.7.tgz#2f61240c8b2b6656233217a8eee07a09a5707fea"
Expand Down

0 comments on commit 5f88020

Please sign in to comment.