Skip to content

Commit 90d73d3

Browse files
docs:25-dịch-3-basic-sveltekit-headers-and-cookies (sveltevietnam#59)
* docs:25-dịch-3-basic-sveltekit-headers-and-cookies * Update content/tutorial/03-sveltekit/04-headers-and-cookies/01-headers/README.md Co-authored-by: Quang Phan <[email protected]> * Update content/tutorial/03-sveltekit/04-headers-and-cookies/01-headers/README.md Co-authored-by: Quang Phan <[email protected]> * Update content/tutorial/03-sveltekit/04-headers-and-cookies/01-headers/README.md Co-authored-by: Quang Phan <[email protected]> * Update content/tutorial/03-sveltekit/04-headers-and-cookies/02-cookies/README.md Co-authored-by: Quang Phan <[email protected]> --------- Co-authored-by: Quang Phan <[email protected]>
1 parent 82c800f commit 90d73d3

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Setting headers
2+
title: Thiết lập các header
33
---
44

5-
Inside a `load` function (as well as in [form actions](the-form-element), [hooks](handle) and [API routes](get-handlers), which we'll learn about later) you have access to a `setHeaders` function, which — unsurprisingly — can be used to set headers on the response.
5+
Bên trong một hàm `load` (cũng như trong [form actions](the-form-element), [hooks](handle) [đường dẫn API](get-handlers), chúng ta sẽ tìm hiểu sau) bạn có quyền truy cập vào hàm `setHeaders` được sử dụng để thiết lập các header _(tiêu đề)_ trên response (phản hồi).
66

7-
Most commonly, you'd use it to customise caching behaviour with the [`Cache-Control`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) response header, but for the sake of this tutorial we'll do something less advisable and more dramatic:
7+
Thường thì bạn sẽ sử dụng nó để tùy chỉnh caching với [`Cache-Control`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control), nhưng trong bài hướng dẫn này, chúng ta sẽ làm một số điều ít được khuyến khích và kịch tính hơn:
88

99
```js
1010
/// file: src/routes/+page.server.js
@@ -15,4 +15,4 @@ export function load(+++{ setHeaders }+++) {
1515
}
1616
```
1717

18-
(You may need to reload the iframe to see the effect.)
18+
(Bạn có thể cần tải lại iframe để thấy tác dụng.)

content/tutorial/03-sveltekit/04-headers-and-cookies/02-cookies/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Reading and writing cookies
2+
title: Đọc và ghi cookies
33
---
44

5-
The [`setHeaders`](headers) function can't be used with the `Set-Cookie` header. Instead, you should use the `cookies` API.
5+
Hàm [`setHeaders`](headers) không thể được dùng với header `Set-Cookie`. Thay vào đó, bạn nên sử dụng API `cookies`.
66

7-
In your `load` functions, you can read a cookie with `cookies.get(name, options)`:
7+
Trong các hàm `load` của bạn, bạn có thể đọc cookie bằng cách sử dụng `cookies.get(name, options)`:
88

99
```js
1010
/// file: src/routes/+page.server.js
@@ -17,7 +17,7 @@ export function load(+++{ cookies }+++) {
1717
}
1818
```
1919

20-
To set a cookie, use `cookies.set(name, value, options)`. It's strongly recommended that you explicitly configure the `path` when setting a cookie, since browsers' default behaviour — somewhat uselessly — is to set the cookie on the parent of the current path.
20+
Để đặt một cookie, sử dụng `cookies.set(name, value, options)`. Khuyến khích bạn nên cấu hình rõ `path` _(đường dẫn)_ khi đặt một cookie, vì hành vi mặc định của trình duyệt — hơi vô ích — là đặt cookie ở phần cha của đường dẫn hiện tại.
2121

2222
```js
2323
/// file: src/routes/+page.server.js
@@ -32,9 +32,9 @@ export function load({ cookies }) {
3232
}
3333
```
3434

35-
Now, if you reload the iframe, `Hello stranger!` becomes `Hello friend!`.
35+
Bây giờ, nếu bạn tải lại iframe, `Chào người lạ!` sẽ trở thành `Chào bạn!`.
3636

37-
Calling `cookies.set(name, ...)` causes a `Set-Cookie` header to be written, but it _also_ updates the internal map of cookies, meaning any subsequent calls to `cookies.get(name)` during the same request will return the updated value. Under the hood, the `cookies` API uses the popular `cookie` package — the options passed to `cookies.get` and `cookies.set` correspond to the `parse` and `serialize` options from the `cookie` [documentation](https://github.com/jshttp/cookie#api). SvelteKit sets the following defaults to make your cookies more secure:
37+
`cookies.set(name, ...)` làm tiêu đề `Set-Cookie` sẽ được ghi, nhưng nó _cũng_ cập nhật bản đồ nội bộ của cookies, có nghĩa là sau đó nếu `cookies.get(name)` được gọi trong cùng một yêu cầu sẽ trả về giá trị đã được cập nhật. Tiến trình này như sau, API `cookies` sử dụng package `cookie` thường gặp — các tùy chọn được truyền vào `cookies.get` `cookies.set` tương ứng với các tùy chọn cho `parse` `serialize` từ [tài liệu](https://github.com/jshttp/cookie#api) của `cookie`. SvelteKit đặt các giá trị mặc định sau để làm cho cookie của bạn an toàn hơn:
3838

3939
```js
4040
/// no-file

content/tutorial/03-sveltekit/04-headers-and-cookies/02-cookies/app-a/src/routes/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
export let data;
33
</script>
44

5-
<h1>Hello {data.visited ? 'friend' : 'stranger'}!</h1>
5+
<h1>Chào {data.visited ? 'bạn' : 'người lạ'}!</h1>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"title": "Headers and cookies"
2+
"title": "Headers cookies"
33
}

0 commit comments

Comments
 (0)