Skip to content

Commit

Permalink
perf: improve create-brisa-app
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Oct 7, 2023
1 parent 86e0e58 commit 6459f78
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ Will be transformed to this HTML in `es`:
As long as you do not put the locale in the `href` of `a` tag, then no conversion is done. It is useful to change the language:

```tsx filename="src/components/change-locale.tsx" switcher
import { type RequestContext } from "brisa";

export function ChangeLocale(props: {}, { i18n, route }: RequestContext) {
const { locales, locale, pages, t } = i18n;

Expand All @@ -675,6 +677,28 @@ export function ChangeLocale(props: {}, { i18n, route }: RequestContext) {
}
```

```js filename="src/components/change-locale.js" switcher
export function ChangeLocale(props: {}, { i18n, route }) {
const { locales, locale, pages, t } = i18n;

return (
<ul>
{locales.map((lang) => {
const pathname = pages[route.name]?.[lang] ?? route.pathname;

if (lang === locale) return null;

return (
<li>
<a href={`/${lang}${pathname}`}>{t(`change-to-${lang}`)}</a>
</li>
);
})}
</ul>
);
}
```
## Leveraging the `BRISA_LOCALE` cookie
Brisa supports overriding the accept-language header with a `BRISA_LOCALE=the-locale` cookie. This cookie can be set using a language switcher and then when a user comes back to the site it will leverage the locale specified in the cookie when redirecting from `/` to the correct locale location.
Expand Down
44 changes: 40 additions & 4 deletions src/create-brisa-app/create-brisa-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ mkdir $PROJECT_NAME

cd $PROJECT_NAME

echo "Creating package.json"
$BRISA_VERSION="0.0.6"

bun init -y
echo "Creating package.json"

echo "Installing brisa"

Expand All @@ -24,7 +24,7 @@ echo "{
\"start\": \"brisa start\"
},
\"dependencies\": {
\"brisa\": \"0.0.6\"
\"brisa\": \"$BRISA_VERSION\"
},
\"devDependencies\": {
\"bun-types\": \"latest\"
Expand Down Expand Up @@ -67,6 +67,39 @@ echo "{
}" > tsconfig.json


echo "# $PROJECT_NAME
## Getting Started
Project created with [Brisa](https://github.com/aralroca/brisa) v$BRISA_VERSION.
### Installation
\`\`\`bash
bun install
\`\`\`
### Development
\`\`\`bash
bun dev
\`\`\`
### Build
\`\`\`bash
bun build
\`\`\`
### Start
\`\`\`bash
bun start
\`\`\`
" > README.md

mkdir src
mkdir src/pages
touch src/pages/index.tsx
Expand All @@ -80,4 +113,7 @@ echo "export default function Homepage() {

bun install

cd ..
cd ..

echo "Project created successfully"
echo "Run: cd $PROJECT_NAME && bun dev"
4 changes: 2 additions & 2 deletions src/create-brisa-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-brisa-app",
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",
"type": "module",
"author": {
Expand All @@ -17,4 +17,4 @@
"bin": {
"create-brisa-app": "./create-brisa-app.sh"
}
}
}

0 comments on commit 6459f78

Please sign in to comment.