nextjs 13, 14 App Directory language without i18n – internalization

Question: Is there a way to do multi-language without i18n since it’s a 2 pages website…

The context

The root layout has the language detection:

1- Using a context that record french if french or else is english.

<script async dangerouslySetInnerHTML={{ __html:(function () {
function setTheme(newTheme) {
window.__theme = newTheme;
window.__onThemeChange(newTheme);
}
// this will be overwritten in our React component
window.__onThemeChange = function () {};

              // this will be triggered by our React component
              window.__setPreferredTheme = function (newTheme) {
                setTheme(newTheme);
                try {
                  localStorage.setItem("lang", JSON.stringify(window.__theme));
                } catch (err) {}
              };

              // detect system theme and monitor for changes
              var darkQuery = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage)
              darkQuery = darkQuery.split('-')[0];

              var preferredTheme;
              // try to get saved theme
              try {
                preferredTheme = JSON.parse(localStorage.getItem("lang"));
              } catch (err) {}  
              // initialize preferredTheme
              setTheme(preferredTheme || darkQuery);
            })();`
          }}
        />

`

The goal is to use the contect “en” or “fr” to render the correct json caracter. At the moment I am stuck at the json part.

How to know the action sent to server by a button on a webpage? do you use a chrome addon for that?

how do you process to know the action sent to the server by this ‘Delete’ button on a webpage? do you use a special Chrome addon?


<div _ngcontent-geev-pwa-ssr-c1357586839="" class="modal-footer glob-font-body-bold">
  <button _ngcontent-geev-pwa-ssr-c1357586839="" type="button" class="modal-footer-cancel">Dismiss</button>
 ** <button _ngcontent-geev-pwa-ssr-c1357586839="" type="button" class="modal-footer-validate"> Delete </button>**
</div>

Screenshot

I have used Chrome built-in inspect tool, but this does not provide me any info about the action being actually requested to the web server, what else can I do to find it?

TypeError: Cannot read properties of undefined (reading ‘roles’) discord.js,, tried so much nothing worked [closed]

const Discord = require('discord.js');
      const client = new Discord.Client({
        intents: [
          Discord.GatewayIntentBits.Guilds,
          Discord.GatewayIntentBits.GuildMembers
        ]
      });
        // Get the guild (server) and role objects
        const guild = client.guilds.cache.get(`${js.guildId}`);
        const role = client.guild.roles.cache.find(role => role.name === `${roleName}`);

        // Get the member object
        const member = guild.members.cache.get(`${js.clientId}`);

        // Add the role to the member
        member.roles.add(role).catch(console.error);

this code give me this error, TypeError: Cannot read properties of undefined (reading ‘roles’).
What i can do?

i tried searching for answer but i didnt get anythibg

POST REQUEST BY NEXT JS 14

how to make POST REQUEST by next js 14 using axios or fetch but i prefer axios,
i try but alway show to me AxiosError: NewWorkError when try fetch show to me typeError: fetch faild

but it success with postman

i want sent request to http://localhost:3001/CreateUser

`
const POST = () => {

const PostRequest = async () => {
    try {
        const response await axios.post("http://localhost:3001/CreateUser", {
        nameOfUser: "mostafa",
        ageOfUser: 22,
        phoneNumber: 201003443454,
        EmailOfUser: "[email protected]",
      })
   } catch(error) {
       console.log(error.message);
   }
}

return <button onClick={() => PostRequest()}>POST</button>

}

export default POST;
`

i research in youtube and ask chat gpt and copilot and try by my self

Highcharts – Export chart with crosshair intact

I am exporting chart with tooltip. I have a fixed tooltip.

Tooltip is generated in the export based on last clicked point in chart.
Rite now, only the point clicked is highlighted in the export. But I want the crosshair as well to be shown in export, so user can clearly see which point was clicked.

Please find the working fiddle with my functionality.
Https://jsfiddle.net/ntye1aL7/2/

Code:

 if (clickedPoint) {
              clickedPoint.setState('hover');
  }

Above is the code that is pulling up tooltip on export. Can we use anything other than setState(‘hover’), so that crosshair functionality is intact. Would appreciate your input. Thanks.

innerHTML not showing up despite it being called

This bug is actually pissing me off lol so i want to make a quiz game and each question will be updated based on the objects inside the question variable and everything is working but num.innerHTML = ${ques.id} and i do not know why

<!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="styles.css">
    </head>
    <body>
        <div class="container">
            <div id="question">
                <div id="num">1.</div>
                <div id="ques">What is 10 x 10</div>
            </div>
            <div id="answers">
                <div id="ans1" class="button">100</div>
                <div id="ans2" class="button">40</div>
                <div id="ans3" class="button">25</div>
                <div id="ans4" class="button">1</div>
            </div>
            <div id="toggle">
                <div id="prev">Prev</div>
                <div id="next">Next</div>
            </div>
        </div>
        
        <script src="script.js" async defer></script>
    </body>
</html>
let score = 0
let i = 0

const prev = document.querySelector("#prev")
const next = document.querySelector("#next")

const num = document.querySelector("#num")
const q = document.querySelector("#question")

const ans1 = document.querySelector("#ans1")
const ans2 = document.querySelector("#ans2")
const ans3 = document.querySelector("#ans3")
const ans4 = document.querySelector("#ans4")

const questions = [
    {
        id: 1,
        q: "What is the capital of Indonesia?",
        a1: "Jakarta",
        a2: "Bandung",
        a3: "Surabaya",
        a4: "Bali",
        c: "Jakarta"
    },
    {
        id: 2,
        q: "Who won the 2017 NBA MVP Award?",
        a1: "Lebron James",
        a2: "Russell Westbrook",
        a3: "Kawhi Leonard",
        a4: "James Harden",
        c: "Russell Westbrook"
    }
]

function update(ques){
    num.innerHTML = `${ques.id}`
    q.innerHTML = ques.q

    ans1.innerHTML = ques.a1
    ans2.innerHTML = ques.a2
    ans3.innerHTML = ques.a3
    ans4.innerHTML = ques.a4
}

update(questions[0])

Do modules run multiple times upon import in a Next.js app?

It is well known that even if a module is imported multiple times in a JavaScript program, it only runs once (for the first import).

Relevant aritcle:

The rules are quite simple: the same module is evaluated only once, in
other words, the module-level scope is executed just once. If the
module, once evaluated, is imported again, it’s second evaluation is
skipped and the resolved already exports are used.

Which is why code written above a React component only runs once, as confirmed in the docs:

Some logic should only run once when the application starts. You can
put it outside your components…this guarantees that such logic only
runs once after the browser loads the page.

My question is related to Next.js on Vercel:

Would imports only run once when the site is built, and never again?

Or does it differ between static and dynamic routes (pages)? I.e. a page, if static, only runs an import upon build, whereas a dynamic route runs the import every time a browser visits the page?

window.localStorage function not working on API Routing NextJS

How to can use window syntax on API Route NextJS?

export async function POST(request: NextApiRequest, response: NextApiResponse<DataResponse>) {
    const dataReq = await request.json();
    window.localStorage('cachestore', JSON.stringify(dataReq));
}

The function window on POST or GET in the Next JS Routing API does not work. However, on a regular page it can run using the useEffect()=>{} function. How can I make it work well when accessing the /api/page page?

Mui dropdown open after 3 input characters but dropdown not closing

I want to close this Mui dropdown when i clicked an option . Currently I can’t close
Is there any way to close this
<Autocomplete
id=’select-status’
freeSolo
options={[‘Active’, ‘InActive’]}
onInputChange={(e, newValue) =>
setPlateFormData({ …plateFormData,IsActive: newValue })}
value={plateFormData.IsActive}
renderInput={(params) =>
<sdkMui.TextField {…params}
size=’small’label=”Status” name=’IsActive’ />}

/>

I want to close the dropdown when i click an optio

Having Trouble Playing Audio in Vue Template

I tried to use the audio tag through the variable, but it didn’t explore. Please help me.

This is in tag script

<script setup>
import { ref } from 'vue'
import data from '../../../data/game3/data2.json'

const music = ref(data.categories[0].units[0].items[0].pronunciation)

console.log(music.value) //when  log it show ../../assets/pronunciation/apple.mp3 which is the right path

</script>

And this is in template tag

<template>
  <div>
    {{ music }}

    <audio controls>
      <source :src="music" type="audio/mp3" />
    </audio>

    <audio controls>
      <source src="../../assets/pronunciation/apple.mp3" type="audio/mp3" />
    </audio>
  </div>

The first one is not working can you guys help me please. (I’ve tried several browsers and they’re all the same.)

firebase storagethat was working fine all of a sudden gives me the following err

chunk-SAKU7T62.js?v=c09a6d03:819 Uncaught Error: Service storage is not available
    at Provider.getImmediate (chunk-SAKU7T62.js?v=c09a6d03:819:15)
    at getStorage (firebase_storage.js?v=c09a6d03:2890:43)
    at firebase.js:32:17

everything is initialized correctly and was working up until last night. I didn’t even change anything related to firebase. and last night boom. I got this error. I tried to roll it back so much further. I tried everything. but it’s still giving me the above error.

I tried rolling it back and tried updating the firebase functions and sdk.

How to merge multiple imported GLTF object into one object in three.js?

The problem is that the website is laggy, becuase I am rendering thousands of objects. I am trying to solve this problem to get better UX.
I am importing 1 GLTF object (myModel). I also have a json file (myJson), which contains how much object and where should I place them. It also contains if the object needs to be rotated.
I think if i could merge all objects into 1, then the website would be not laggy.
How could I do that?
The whole js code:

import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import myJson from './output.json';

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);

document.body.appendChild(renderer.domElement);

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
    45,
    window.innerWidth / window.innerHeight,
    0.1,
    1000
);
camera.position.set(10, 10, 10);
const orbit = new OrbitControls(camera, renderer.domElement);
orbit.update();

const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);

const assetLoader = new GLTFLoader();
let model = null

assetLoader.load("./myModel.gltf", function (gltf) {
    model = gltf.scene;

    let objects = []

    if (model) {
        for (let i = 0; i < myJson.length; i++) {
            let XCoordinate = myJson[i].XCoordinate
            let YCoordinate = myJson[i].YCoordinate

            let myModel = model.clone()
            objects.push(myModel)
            objects[objects.length - 1].position.set(XCoordinate, 0, YCoordinate);
            scene.add(objects[objects.length - 1]);
        }
        for (let i = 0; i < objects.length; i++) {
            if (myJson[i].needRotate) {
                objects[i].rotateX(Math.PI / 2)
            } else {
                objects[i].rotateX(-Math.PI / 2)
            }
        }
    }

}, undefined, function (error) {
    console.error(error);
});



function animate() {
    renderer.render(scene, camera);
    requestAnimationFrame(animate);
};
animate();

window.addEventListener('resize', function () {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight);
});

RTK Query: Should I use same query for different endpoints if they all have same data structure?

On our project we use RTK Query and we have the following situation:

On back wed we have endpoints, for simplicity, /api/green/cars/, /api/blue/cars and /api/red/cars that share the same data structure.

My colleagues couldn’t agree whether we should create 3 separate RTK endpoints for them: getGreenCars, getBlueCars, getRedCars with static urls or if we should create one endpoint with a dynamic address:

getCars: build.query({
  query: (color) => ({
    url: `/api/${color}/cars`
    method: 'GET'
  })
})

Those who favor the one endpoint solution say that it will allow us to avoid code duplication.

Those who favor the multiple endpoints solution say that it will keep our code more clear (one rtk endpoint per one back end endpoint) as well as we will be able to implement tags properly (there will be POST, PUT and DELETE too, so we have to keep that in mind).

We are pretty much in a deadlock so I wonder if anyone knows a good piece of theory about this or has experienced something similar so there is an unambiguous decision for this situation.

Mechanism for online photo broadcasting from browser to smartphone [closed]

There is a browser. (js)
There’s a server. (golang)
There is an android smartphone. (c++)
Task: Broadcasting photo-video from a browser to a smartphone without loss of quality and resolution of the image.
I want to know modern methods of realization of this task. How can I realize the broadcast with minimal delay.
At the same time we should take into account that AOSP by standard is limited by the availability of libraries.

Now on the site I have created a canvas within which I am able to scale the image and move it within the canvas. Recursively js function takes the image blob from the canvas and sends it with websocket to the server. The server runs on golang, this language was chosen because of its simplicity and fast speed. The server takes the blob image, converts it to a YUV image, divides the image into 4 parts and sends simultaneously 4 separate threads using tcp to 4 different ports. The smartphone has 4 ports open, 4 independent threads that receive the image, connect the image and the output is a whole image with no loss of quality.
For example I sent a 3000x4000px image from my browser, that’s the image I got on my smartphone.
As a result I have a big delay. I am testing on a local network. And if I test remotely via the Internet, the delay will be even greater. And this is me sending a photo with online editing. And if I send video frame by frame, then the delay will be even greater.
Please point out my mistakes. Perhaps there are ways of better realization of the task.