aymericzip/intlayer-skills / skills/intlayer-content
intlayer-content
VerifiedDefine rich content structures using Intlayer content nodes. Use when the user asks to "create translations", "handle pluralization", "use markdown in content", or implement "conditional content".
| File | Kind | Size |
|---|---|---|
| LICENCE.md | markdown | 10.7 KB |
| SKILL.md | skill md | 12.0 KB |
| references/concept_content.md | markdown | 35.4 KB |
| references/concept_content_condition.md | markdown | 7.7 KB |
| references/concept_content_enumeration.md | markdown | 13.6 KB |
| references/concept_content_file.md | markdown | 8.4 KB |
| references/concept_content_function-fetching.md | markdown | 4.6 KB |
| references/concept_content_gender.md | markdown | 7.9 KB |
| references/concept_content_html.md | markdown | 22.7 KB |
| references/concept_content_insertion.md | markdown | 4.7 KB |
| references/concept_content_markdown.md | markdown | 47.2 KB |
| references/concept_content_nesting.md | markdown | 8.7 KB |
| references/concept_content_plural.md | markdown | 11.3 KB |
| references/concept_content_select.md | markdown | 10.6 KB |
| references/concept_content_translation.md | markdown | 6.1 KB |
| references/concept_per-locale-file.md | markdown | 7.6 KB |
| references/packages_intlayer_exports.md | markdown | 12.4 KB |
references/concept_content_file.md
View on GitHub---
createdAt: 2025-03-13
updatedAt: 2026-09-27
priority: 8
title: "File Content: Embed External Files"
description: "Embed external files such as markdown or text into your Intlayer dictionaries with the file() function, kept in sync with the source file."
keywords:
- File
- Internationalization
- Documentation
- Intlayer
- Next.js
- JavaScript
- React
slugs:
- doc
- concept
- content
- file
history:
- version: 5.5.10
date: 2025-06-29
changes: "Init history"
author: aymericzip
---
# File Content / Embedding Files in Intlayer
In Intlayer, the `file` function allows embedding external file content into a dictionary. This approach ensures that Intlayer recognizes the source file, enabling seamless integration with the Intlayer Visual Editor and CMS.
## Why using `file` instead of `import`, `require`, or `fs`?
Unlike `import`, `require`, or `fs` file reading methods, using `file` associates the file with the dictionary, allowing Intlayer to track and update the content dynamically when the file is edited. As a result, using file will offer better integration with the Intlayer Visual Editor and CMS.
## Setting Up File Content
To embed file content in your Intlayer project, use the `file` function in a content module. Below are examples demonstrating different implementations.
```typescript fileName="**/*.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
import { file, type Dictionary } from "intlayer";
const myFileContent = {
key: "my_key",
content: {
myFile: file("./path/to/file.txt"),
},
} satisfies Dictionary;
export default myFileContent;
```
```json5 fileName="**/*.content.json" contentDeclarationFormat="json"
{
"$schema": "https://intlayer.org/schema.json",
"key": "my_key",
"content": {
"myFile": {
"nodeType": "file",
"value": "./path/to/file.txt",
},
},
}
```
## Using File Content
<Tabs group="framework">
<Tab label="React" value="react">
To use embedded file content in a React component, import and use the `useIntlayer` hook from the `react-intlayer` package. This retrieves the content from the specified key and allows it to be displayed dynamically.
```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const FileComponent: FC = () => {
const { myFile } = useIntlayer("my_key");
return (
<div>
<pre>{myFile}</pre>
</div>
);
};
export default FileComponent;
```
</Tab>
<Tab label="Next.js" value="nextjs">
To use embedded file content in Next.js Client Components, retrieve it via the `useIntlayer` hook. Here's an example:
```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
"use client";
import type { FC } from "react";
import { useIntlayer } from "next-intlayer";
const FileComponent: FC = () => {
const { myFile } = useIntlayer("my_key");
return (
<div>
<pre>{myFile}</pre>
</div>
);
};
export default FileComponent;
```
</Tab>
<Tab label="Vue" value="vue">
To use embedded file content in Vue components, retrieve it via the `useIntlayer` hook. Here's an example:
```vue fileName="**/*.vue"
<script setup lang="ts">
import { useIntlayer } from "vue-intlayer";
const { myFile } = useIntlayer("my_key");
</script>
<template>
<div>
<pre>{{ myFile }}</pre>
</div>
</template>
```
</Tab>
<Tab label="Svelte" value="svelte">
To use embedded file content in Svelte components, retrieve it via the `useIntlayer` hook. The store is accessed with `$`. Here's an example:
```svelte fileName="**/*.svelte"
<script lang="ts">
import { useIntlayer } from "svelte-intlayer";
const content = useIntlayer("my_key");
</script>
<div>
<pre>{$content.myFile}</pre>
</div>
```
</Tab>
<Tab label="Preact" value="preact">
To use embedded file content in Preact components, retrieve it via the `useIntlayer` hook. Here's an example:
```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
import type { FC } from "preact";
import { useIntlayer } from "preact-intlayer";
const FileComponent: FC = () => {
const { myFile } = useIntlayer("my_key");
return (
<div>
<pre>{myFile}</pre>
</div>
);
};
export default FileComponent;
```
</Tab>
<Tab label="Solid" value="solid">
To use embedded file content in SolidJS components, retrieve it via the `useIntlayer` hook. Here's an example:
```tsx fileName="**/*.tsx" codeFormat={["typescript", "esm"]}
import type { Component } from "solid-js";
import { useIntlayer } from "solid-intlayer";
const FileComponent: Component = () => {
const { myFile } = useIntlayer("my_key");
return (
<div>
<pre>{myFile}</pre>
</div>
);
};
export default FileComponent;
```
</Tab>
<Tab label="Angular" value="angular">
To use embedded file content in Angular components, retrieve it via the `useIntlayer` hook. Here's an example:
```typescript fileName="app.component.ts" codeFormat="typescript"
import { Component } from "@angular/core";
import { useIntlayer } from "angular-intlayer";
@Component({
selector: "app-file",
template: `
<div>
<pre>{{ content().myFile }}</pre>
</div>
`,
})
export class FileComponent {
content = useIntlayer("my_key");
}
```
</Tab>
<Tab label="Vanilla JS" value="vanilla">
To use embedded file content with `vanilla-intlayer`, retrieve it via the `useIntlayer` hook. Here's an example:
```typescript fileName="**/*.ts" codeFormat={["typescript", "esm"]}
import { installIntlayer, useIntlayer } from "vanilla-intlayer";
installIntlayer();
const content = useIntlayer("my_key").onChange((newContent) => {
document.getElementById("file-content")!.textContent = newContent.myFile;
});
// Initial render
document.getElementById("file-content")!.textContent = content.myFile;
```
</Tab>
</Tabs>
## Multilingual Markdown Example
To support multilingual editable Markdown files, you can use `file` in combination with `t()` and `md()` to define different language versions of a Markdown content file.
```typescript fileName="**/*.content.ts" contentDeclarationFormat={["typescript", "esm", "commonjs"]}
import { file, t, md, type Dictionary } from "intlayer";
const myMultilingualContent = {
key: "my_multilingual_key",
content: {
myContent: md(
t({
en: file("src/components/test.en.md"),
fr: file("src/components/test.fr.md"),
es: file("src/components/test.es.md"),
})
),
},
} satisfies Dictionary;
export default myMultilingualContent;
```
This setup allows the content to be dynamically retrieved based on the user's language preference. When used in the Intlayer Visual Editor or CMS, the system will recognize that the content comes from the specified Markdown files and ensure they remain editable.
## Different types of paths
When using the `file` function, you can use different types of paths to specify the file to embed.
- `file("./path/to/file.txt")` - Relative path to the current file
- `file("path/to/file.txt")` - Relative path to the project root directory
- `file("/users/username/path/to/file.txt")` - Absolute path
## How Intlayer Handles File Content
The `file` function is based on Node.js' `fs` module to read the content of the specified file and insert it into the dictionary. When used in conjunction with the Intlayer Visual Editor or CMS, Intlayer can track the relationship between the dictionary and the file. This allows Intlayer to:
- Recognize that the content originates from a specific file.
- Automatically update the dictionary content when the linked file is edited.
- Ensure synchronization between the file and the dictionary, preserving the integrity of the content.
## Additional Resources
For more details on configuring and using file embedding in Intlayer, refer to the following resources:
- [Intlayer CLI Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/cli/index.md)
- [React Intlayer Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_create_react_app.md)
- [Next Intlayer Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_15.md)
- [Markdown Content Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/markdown.md)
- [Translation Content Documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/dictionary/translation.md)
These resources provide further insights into file embedding, content management, and Intlayer’s integration with various frameworks.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |