How to add metadescription translation in astro with i18next? - astrojs

I am trying to translate my meta per page but I get stuck or error there is my code layout.astro
---
import i18next from "i18next";
export interface Props {
title: string;
}
const { title } = Astro.props as Props;
---
<!DOCTYPE html>
<html lang={i18next.language}>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
and there my index.astro
<Layout title={t("pageTitle")} description={t("pageMeta")}>
Any idea Thanks
I am trying to translate my metadescription page by page with i18next in astro.bluid

Related

Spring MVC and Thymeleaf - only classpath mapping works

I wonder why I have to add "classpath:" always int he resourcelocations mapping for Spring, is this best practice?
Currently my project is setup like this, but I if I remove the "classpath", it does not find anything (and also I cannot provide a proper direct link). For integating bootstrap, I even had to use "webjars-locator" to make webjars accessible (due to missing transparency).
Can anyone explain, why classpath is required (and no direct link), and how I can find or restrucutre the project to make it work properly?
ResourceHandlers:
#Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler(
"/webjars/**",
"/img/**",
"/css/**",
"/js/**")
.addResourceLocations(
"classpath:/META-INF/resources/webjars/",
"classpath:/static/img/",
"classpath:/static/css/",
"classpath:/static/js/");
}
index.htm:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Spring Security Example</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" th:href="#{/css/style.css}" />
<link rel="stylesheet" type="text/css" th:href="#{/webjars/bootstrap/4.2.1/css/bootstrap.min.css}" />
</head>
<body>
<h1 class="color1">Hello, world! style</h1>
<p>
Click <a th:href="#{/hello}">here</a> to see a greeting.
</p>
<!-- include javascript in the footer -->
**<script type="text/javascript" th:src="#{/webjars/jquery/3.2.1/jquery.min.js}"></script>
<script type="text/javascript" th:src="#{/webjars/bootstrap/4.2.1/js/bootstrap.min.js}"></script>**
</body>
</html>
It is normal to use classpath. If you want to additionally load resources from root path use
{"/", "classpath:/META-INF/resources/webjars/" ...}

Undefined variable: header (View: C:\blog\resources\views\pages\welcome.blade.php)

I am getting the below error when running application,
Undefined variable: header (View: C:\blog\resources\views\pages\welcome.blade.php)
My getIndex() function in Controller:
public function getIndex(){
\View::make('pages/welcome')->nest('header', 'layout.header');
return view('pages/welcome');
}
My welcome.blade.php
{{ $header }}
<body>
....
</body>
My _partial/header.blade.php,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Blog Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
</head>
After following the answer, the html looks like,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Blog Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="http://127.0.0.1:8000/css/style.css" rel="stylesheet">
</head>
You're creating a view with a nested subview, then creating & returning a totally new view without the nested subview instead:
public function getIndex(){
\View::make('pages/welcome')->nest('header', 'layout.header');
return view('pages/welcome');
}
Should be
public function getIndex(){
return \View::make('pages/welcome')->nest('header', 'layout.header');
}
Note that view() is an alias of \View::make().
You can prevent the HTML from being escaped by using {!! $header !!} instead.
With Laravel 5+ development, you should be using Components and Slots to inject templates into your views instead.

extending fragments in Thymeleaf

I have the following fragment. I'm trying to extend the base fragment "head" with the open graph tags... but the rendered page contains only tags from fragments/head, with the og ones.
How can I add more tags to a fragment?
<head th:include="fragments/head :: head">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="GUApp" />
<meta property="og:description" th:content="${description}" />
<!--<meta property="og:image" content="http://www.your-domain.com/path/image.jpg" />-->
</head>
<head th:fragment="head" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
....
</head>
The easiest option is to pass additional tags as in Flexible layouts documentation demo.
Thanks to fragment expressions, we can specify parameters for
fragments that are not texts, numbers, bean objects… but instead
fragments of markup.
This allows us to create our fragments in a way such that they can be
enriched with markup coming from the calling templates, resulting in a
very flexible template layout mechanism.
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="header :: head(~{::meta})">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description" th:content="${description}"/>
</head>
...
header.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:fragment="head(meta)">
<!-- some default styles -->
<link href="base.css" rel="stylesheet" />
<!--/* Per-page placeholder for additional meta tags */-->
<th:block th:replace="${meta}" />
</head>
...
Result html:
<!DOCTYPE html>
<html lang="en">
<head>
<link href="base.css" rel="stylesheet" />
<meta property="og:url"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description"/>
</head>
...

Spring Boot Thymeleaf Layout Dialect Not Working

I just created a new Spring Boot v1.5 project and facing issue where Thymeleaf Layout Dialect is not working.
I have the dependencies in my build.gradle and its on the classpath.
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.1.2'
I have the following layout file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8" />
<title>Default Template</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="" />
<meta name="description" content="" />
<meta name="title" content="" />
<link rel="stylesheet" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<!-- header -->
<header th:include="shared/nav-menu :: menu-admin" />
<!-- page content -->
<th:block>
<section layout:fragment="content"></section>
</th:block>
</body>
</html>
And file with content:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default">
<head>
<title>Parameter Manager</title>
</head>
<body>
<section layout:fragment="content">
<h2>OMG I am on the page!</h2>
</section>
</body>
</html>
The HTML output is content.html file. It is not working as intended. The header and navigation menu should be part of the HTML output. Also the is in the page source which should not be the case.
Apparently the latest version of Thymeleaf Layout Dialect doesn't work with Spring Boot 1.5. Using version 1.2.9 and it works as expected.
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '1.2.9'

Code Igniter lose charset

I'm using codeigniter but it loses charset every time.
What can cause this?
For example:
At my address bar
www.abc.com/def
www.abc.com/def/
My db is UTF-8
My config file - $config['charset'] = 'ISO-8859-1';
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
</body>
</html>
take a look at meta charset part

Resources