[Feature Request] Change names of objects in the hierarchy (eg, "Books" to "Products")
It would be valuable to have a simple UI-accessible way to rename the types of objects in the wiki hierarchy. I wanted to change from Books -> Chapters -> Pages, to Products -> Features -> Pages. I had to change these in the localization files so it'd be nice to have a simpler way to mass-change these names.
it's about time that its author, @ssddanbrown stopped being modest and stubborn and realized that he's already won his crowd of customers. And ease off the idea of "getting there by being different". Bookstack's already "there".
Ooof. It's never been about winning "his crowd of customers". That is almost opposite to the fact, My focus has been supporting the existing user-base that's happy with the current configuration and idea of what BookStack is.
there are no other wiki's like Bookstack, both UI/UX wise with similar structure and usefulness
other wiki's are worse in various fields (taste and usability being among them)
There's a reason for this. As you travel down the path of making a platform more customizable and extensible, it becomes very difficult for the "core" not to become more abstract & plain. Each option or configuration is another branch of logic to support and test, and these things can exponentially add up. BookStack is only in the state that it is right now due to starting off being opinionated.
Just to confirm, It's not that I don't see the need and I'm not saying this will never happen. As new things are developed I generally am implementing them in a more open manner. You can already override all text and icons. When I come to re-thinking the URLs I'll likely have this kind of thing in mind, but it's all a matter to judging the worth of a feature against the cost of maintenance & support (Not just the initial implementation, that's usually the lesser concern).
All I had to do to remap the names of the entities(Shelves, Books, Pages, etc.) is to copy entities.php file from the source code at resources/lang/de/entities.php, modify the names and then add an extra line to the docker-compose.yml
volumes:
- ./bookstack/:/config
- ./entities.php:/var/www/html/resources/lang/de/entities.php
In my case I modified and mapped the german version of entities.php since my Bookstack instance's default language is set to German.
We can't use it unfortunaltely due to "book" and "shelves". What a pitty...We thought this was a KB.
If you put the following code in the <head> element (Settings -> Customization -> Custom HTML Head Content), you can replace all occurrences of "books", "shelves" etc. I'm definitely not proud of this code, but hey, it works 😂
The performance is not even that bad on my machine. Because we're hacking this into the frontend using the custom HTML feature, it won't break your BookStack instance when you update. Of course this solution isn't ideal, but in my case it's good enough (for now).
The dirty fix:
<script>
var replace = {
"shelves": "categories",
"shelf": "category",
"books": "topics",
"book": "topic",
"chapters": "sections",
"chapter": "section"
}
var regex = new RegExp(Object.keys(replace).join("|"),"gi");
function walkText(node) {
if (node.className == "tri-layout-middle") {
return;
}
if (node.nodeType == 3) {
node.data = node.data.replace(regex, function(matched) {
const replaced = replace[matched.toLowerCase()];
if (matched.charAt(0) === matched.charAt(0).toUpperCase()) {
return capitalizeFirstLetter(replaced);
} else {
return replaced;
}
});
}
if (node.nodeType == 1 && node.nodeName != "SCRIPT") {
for (var i = 0; i < node.childNodes.length; i++) {
walkText(node.childNodes[i]);
}
}
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
window.onload = function() {
walkText(document.body);
};
</script>
thx @Mauricevb
I realize that the issue is closed but just wanted to add a +1 for a feature like this. Our organisation is considering using the application for documentation, but the used taxonomy with shelves, books etc. is something that is considered problematic. Our concern is whether the users understand it well enough. We are considering maintaining our own translation (I already did some work with the Finnish translation), but are not sure if we want the extra burden when upgrading.
Anyway, thanks for the nice and clean software!
I liked the software for our needs. Deployed it and works wells on a test server. But I think it might not go to prod because of the ability to change super simple taxonomies like books, shelves etc. For SaaS companies, this I think is a must have! Anyways, kudos for the open-source community for building this!
If you put the following code in the
<head>element (Settings -> Customization -> Custom HTML Head Content), you can replace all occurrences of "books", "shelves" etc.
If it helps anyone else, I found that this solution was also replacing the word bookstack in any article to topicstack. Updating the regex in line 9 to an exact match prevented this:
var regex = new RegExp("\\b(" + Object.keys(replace).join("|") + ")\\b", "gi");
I'd be interested in this too (customization of the fixed 'Shelves' and 'Books' names, which don't fit our usecase). Every feature request seems to be redirected to this closed one, which suggests, that this is not supported, and currently not planned to be supported officially, is that correct?
@Flavelius correct.
I would like to +1 this as well, since our organization is using those for our documentation.
While we understand the terminology, our specific use case would be better suited with changed terminology.
If you put the following code in the
<head>element (Settings -> Customization -> Custom HTML Head Content), you can replace all occurrences of "books", "shelves" etc. I'm definitely not proud of this code, but hey, it works 😂 The performance is not even that bad on my machine. Because we're hacking this into the frontend using the custom HTML feature, it won't break your BookStack instance when you update. Of course this solution isn't ideal, but in my case it's good enough (for now).The dirty fix:
<script> var replace = { "shelves": "categories", "shelf": "category", "books": "topics", "book": "topic", "chapters": "sections", "chapter": "section" } var regex = new RegExp(Object.keys(replace).join("|"),"gi"); function walkText(node) { if (node.className == "tri-layout-middle") { return; } if (node.nodeType == 3) { node.data = node.data.replace(regex, function(matched) { const replaced = replace[matched.toLowerCase()]; if (matched.charAt(0) === matched.charAt(0).toUpperCase()) { return capitalizeFirstLetter(replaced); } else { return replaced; } }); } if (node.nodeType == 1 && node.nodeName != "SCRIPT") { for (var i = 0; i < node.childNodes.length; i++) { walkText(node.childNodes[i]); } } } function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } window.onload = function() { walkText(document.body); }; </script>
i think it's the simplest solution for now. is there any update that i missed?
To apply same replacements to browser tab title add this
let title = document.title.split("|").map(chunk => chunk.trim());
if(replace[title[0].toLowerCase()]){
document.title = capitalizeFirstLetter(replace[title[0].toLowerCase()]) + " | " + title[1];
}
right before line
var regex = new RegExp(Object.keys(replace).join("|"),"gi");
Also I recommend change window.onload = function(){} to window.addEventListener('DOMContentLoaded', function(){}) because first waits for images and static resources loading and old titles blink on screen, but DOMContentLoaded called when html DOM is ready and it's much sooner
building off of @sand123 Added checks to not modify document text.
<script>
// ============================
// Replacement Terms
// ============================
// These redefine BookStack's default terms into business-relevant ones
const replace = {
"shelves": "departments", // Top-level: entire groups or divisions
"shelf": "department",
"books": "manuals", // Collections of structured content
"book": "manual",
"chapters": "procedures", // Sections inside a manual
"chapter": "procedure"
};
// Build a regex to match any of the above keys, word-boundary safe and case-insensitive
const regex = new RegExp(`\\b(${Object.keys(replace).join("|")})\\b`, "gi");
// ============================
// Formatting
// ============================
// Capitalizes just the first letter of a string
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// Checks whether a node is inside actual editable page content (to be excluded from changes)
function isInContentArea(node) {
const main = node.closest('main');
return main && main.querySelector('.page-content'); // Only skip areas that have .page-content
}
// ============================
// Text Replacement
// ============================
function walkText(node) {
// Tags that should never be touched (scripts, inputs, code, etc.)
const skipTags = ["SCRIPT", "STYLE", "NOSCRIPT", "INPUT", "TEXTAREA", "CODE", "PRE", "KBD"];
if (skipTags.includes(node.nodeName)) return;
// Skip anything inside editable page content areas
if (node.closest && isInContentArea(node)) return;
// For text nodes, apply the replacement logic
if (node.nodeType === 3) {
node.data = node.data.replace(regex, function(matched) {
const replacement = replace[matched.toLowerCase()];
return matched.charAt(0) === matched.charAt(0).toUpperCase()
? capitalizeFirstLetter(replacement) // Preserve capitalization
: replacement;
});
}
// For element nodes, recursively walk through child nodes
if (node.nodeType === 1) {
for (let i = 0; i < node.childNodes.length; i++) {
walkText(node.childNodes[i]);
}
}
}
// ============================
// On Page Load
// ============================
window.addEventListener('DOMContentLoaded', function () {
// Update the page title if the first chunk matches a replaceable term
let titleParts = document.title.split("|").map(t => t.trim());
if (replace[titleParts[0].toLowerCase()]) {
titleParts[0] = capitalizeFirstLetter(replace[titleParts[0].toLowerCase()]);
document.title = titleParts.join(" | ");
}
// Begin DOM walk from the body, replacing only where allowed
walkText(document.body);
});
</script>
This is best done through renaming things in the locale. I have added a zip with the following renames: "shelves": "categories" "shelf": "category" "books": "topics" "book": "topic" "chapters": "sections" "chapter": "section"
To employ it:
- make a new dir /www/themes/<theme_name>/lang/en/
- extract and copy contents of en.zip (PHP files only) into /www/themes/<theme_name>/lang/en/
- add to bookstack env variables: APP_THEME=<theme_name>
I have tested this with Docker Compose, but it should work in every environment. You should figure out the folder locations, where to define env variables yourself, for how you launch the project.
@regmeg thanks for sharing this! @ssddanbrown has a few demo's on YouTube that covers this topic in full, https://www.youtube.com/watch?v=gLy_2GBse48 https://www.youtube.com/watch?v=Tf74_2iphz0