I use t() function to translate text.
The function is acting like there are no locales in astros /public folder.
My file structure
My translation.json file for en:
{
"index": {
"testHeader": "Test Header"
}
}
Here is my index page code:
---
import Layout from "../layouts/Layout.astro";
import { t, changeLanguage } from "i18next";
changeLanguage("en");
---
<Layout>
<h1>{t("index.testHeader")}</h1>
</Layout>
My astro-i18next.config.mts:
/** #type {import('astro-i18next').AstroI18nextConfig} */
export default {
defaultLocale: "en",
locales: ["en", "cs"],
};
My astro.config.mjs:
import { defineConfig } from 'astro/config';
import astroI18next from "astro-i18next";
import tailwind from '#astrojs/tailwind';
// https://astro.build/config
import react from "#astrojs/react";
// https://astro.build/config
export default defineConfig({
integrations: [astroI18next(), react(), tailwind({
config: './tailwind.config.cjs',
})]
});
the t() function shows the passed key instead of translation.
I runned npx astro-i18next generate which did nothing
I had a similar issue; I fixed it with a config change and a downgrade.
(since it's still in beta, gotta keep an eye on that)
NOTE: The current version of "astro-i18next" is "1.0.0-beta.17".
Add the following to your astro-i18next.config.*: baseLanguage: "en"
Downgrade your version to 1.0.0-beta.13, between versions 10 to 17 only this one worked for me.
Good but not Necessary: add this to your package.json scripts: "i18n": "npx astro-i18next generate"
Run this command and should be successful: pnpm i && pnpm run i18n && pnpm run build
Considering this fix, I'm looking forward for similar issues to be resolved in stable release; However, for the time being this should get you going.
I fixed it using npm update.
For some reason my app's dependencies weren't updated.
modules present in requirements.txt
asgiref==3.5.2
backports.zoneinfo==0.2.1
Django==4.0.5
djangorestframework==3.13.1
djangorestframework-simplejwt==5.2.0
PyJWT==2.5.0
pytz==2022.2.1
sqlparse==0.4.2
configuration in setting.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASS':
['rest_framework_simplejwt.authentication.JWTAuthentication',],
}
After having all proper configuration when i try to import the simplejwt views it is not resolved.
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
Try to mark the Project Directory as source root directory and in pycharm or ide ignore the unresolved error. It will run
When I try to run a functional test which uses the class TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase I get an error Class 'TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase' not found.... Is this an composer autoloader problem? Any Ideas how to fix this?
/usr/bin/php7.4 /mypath/typo3_10/vendor/phpunit/phpunit/phpunit --bootstrap /mypath/typo3_10/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php --configuration /mypath/typo3_10/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml /mypath/typo3_10/web/typo3/sysext/seo --teamcity
is the command in PHPStorm.
"autoload-dev": {
"psr-4": {
"TYPO3\\CMS\\Frontend\\Tests\\": "web/typo3/sysext/frontend/Tests/",
"TYPO3\\CMS\\Core\\Tests\\": "web/typo3/sysext/core/Tests/"
}
}
the solution is to add the missing Namespaces to the root composer.json and dump the autoloader again
I setup a test with Detox, but when I launch it with detox test, the test starts but I receive this error:
Couldn't find preset "module:react-native-dotenv" relative to directory "/Users/iota/workspace/Project"
In the scene file I am trying to test I have this:
import { BASE_URL, GOOGLE_APP_ID } from 'react-native-dotenv';
My .babelrc file:
{
"presets": [
"module:react-native-dotenv",
"module:metro-react-native-babel-preset"
]
}
Any hint?
UPDATE
If I remove the line module:react-native-dotenv, I have a similar error for the module:metro-react-native-babel-preset
You need to install the presets using npm, so a
npm install --save-dev metro-react-native-babel-preset react-native-dotenv
should solve the issue.
App
|-- application
|-- config
| |-- themes.js
| |-- redux.js
+-- views
| |-- login
| | |-- login.js
|-- index.js
index.js
....
import themes from './config/themes';
import themes from './config/redux';
...
login.js
....
import themes from '../../config/themes';
import themes from '../../config/redux';
...
I hope it like this:
....
import themes from '#root/application/config/themes';
import themes from '#root/application/config/redux';
import ... from '#root/...';
...
if methods of php
$root = 'User/React-Native-Project/';
include $root.'/application/config/themes.php';
This can improve the development efficiency and avoid the wrong path and other issues.my english is not good.
Alias in React Native
There is a point where you will have multiple files and folder in your project. And we need to get the reference of one file from another in any random possibilities. If we are following the relative path such as
import themes from '../../config/themes';
then it’s really very hard for us to get an idea where it takes by the symbol ‘../ ‘ and in more complex project this is a night mare.
In this post we will find the possible solution and alternative on this type of scenario. Let’s take an example project with following folder structure.
Your App Root Directory
|-- app
|-- component
| |-- login
| | |-- login.js
+-- resources
| |-- icon
| | |-- userupload.png
|-- index.ios.js
|-- index.android.js
We have two possible solution to point each node in the above folder structure.
Use #providesModule (update: will not work for RN versions 56 and above. https://github.com/facebook/react-native/issues/21152)
A secondary solution that would work but is less “safe”, is to use #providesModule in your file. This comes with less boilerplate but since it’s based on Facebook’s own internal use case, it could change based on their internal whim. You can read more about it here:https://github.com/facebook/fbjs
To use it you need to include this comment at the top of your file:
/**
* #providesModule login
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
export default class login extends Component{
render(){
return(
<View>
<Text> this is login page
</Text>
</View>
);
}
}
Then you can import it the same as above:
import themes from 'login';
Use babel-plugin-module-alias
A babel plugin to rewrite (map, alias, resolve) directories as different directories during the Babel process. It’s particularly useful when you have files you don’t want to use with relative paths (especially in big projects).
Uses:
Install babel cli
npm install --g babel-cli
Install babel-plugin-module-alias.
$ npm install --save babel babel-plugin-module-alias
Create a file .babelrc in root directory or add a key babel: your project’s package.json and add following lines of code.
"babel":{
"plugins": [[
"module-alias", [
{ "src": "./app", "expose": "app" },
{ "src": "./app/resources/icon", "expose": "icon" }
]
]]
}
and finally clear the cache and restart the node server
npm start -- --reset-cache
Full source code can be downloaded from here
use babel-plugin-module-alias
npm install --save babel babel-plugin-module-alias
create a .babelrc file for project root directory.
{
"presets": [
"react-native"
],
"plugins": [
["babel-plugin-module-alias", [
{ "src": "./application", "expose": "app" }
]]
]
}
start command:
npm start -- --reset-cache
Now we can do the:
....
import themes from 'app/config/themes';
import themes from 'app/config/redux';
import ... from 'app/...';
...
Use babel-plugin-module-resolver.
The existing answers were long-winded, outdated and made it way more complicated than it needs to be. I felt obligated to add a succinct answer to help others.
Install the package:
npm install --save-dev --save-exact babel-plugin-module-resolver
Modify or create a .babelrc file in your root directory with the following:
{
"plugins": [
[ "module-resolver", { "root": ["./"] } ]
]
}
You can change ./ to the root of your code, like ./application or something.
Update your import paths:
Instead of writing:
import themes from '../../config/themes';
You can write this:
import themes from 'config/themes';
Profit!
You can create a package.json file containing {"name": "root"} in your root folder. Note that this may be a different file than the original 'package.json' that every project has.
And in case you want to use another folder named X populate the package.json with {"name": "X"}. so now you can simply use import foo from 'X/foo' in your project.
For more information check these:
https://github.com/facebook/react-native/issues/3099#issuecomment-221815006
https://medium.com/#davidjwoody/how-to-use-absolute-paths-in-react-native-6b06ae3f65d1
I see 2 solutions to accomplish what you want:
1) Create a "themes" package
One thing that's nice about the React Native packager is that it will pick up any "packages" (or "node modules") that are anywhere in your project directory structure.
This means that in your config directory, you could have a themes directory with a package.json (with a "name" field of 'themes') and an index.js (the index.js would contain the code that you now have in 'application/config/themes'.)
Then, when you want to import this code you can simply do:
import themes from 'themes';
Remember, you can place this "package" anywhere you want in your directory structure. While this isn't "exactly" what you were looking for, it is definitely a working solution.
2) Use #providesModule(update: will not work for RN versions 56 and above. https://github.com/facebook/react-native/issues/21152)
A secondary solution that would work but is less "safe", is to use #providesModule in your file. This comes with less boilerplate but since it's based on Facebook's own internal use case, it could change based on their internal whim. You can read more about it here: https://github.com/facebook/fbjs
To use it you need to include this comment at the top of your file:
/**
* #providesModule themes
*/
Then you can import it the same as above:
import themes from 'themes';
Here is an example of it being used in the React Native project itself: https://github.com/facebook/react-native/blob/master/Libraries/Text/Text.js#L9
This actually isn't really about React Native. I think that it's more of a Babel question. The answer is actually quite simple—use the Module Resolver package. This allows one to configure a module-specifier-to-URL resolver for use by Babel. It's especially useful for avoiding relative URLs.
First, execute the following command:
$ npm install --save-dev babel-plugin-module-resolver
Then, in your ".babelrc" file or in a babel attribute of your project's "package.json" file, specify the options for the plugin:
"plugins": [[
"module-resolver", {
"root": ["./application"]
}
]]
Finally, clear the cache and restart the node server
$ npm start -- --reset-cache
To use the babel plugin, you need the babel-preset-react-native :
Add babel-preset-react-native:
$ npm i --save-dev babel-preset-react-native babel-plugin-module-alias
Add .babelrc
```
{
"presets": ["react-native"],
"plugins": [
["module-alias", [
{ "src": "./app", "expose": "app" }
]]
]
}
```
react-native run-ios
See:
https://www.npmjs.com/package/babel-preset-react-native
https://github.com/tleunen/babel-plugin-module-alias