import os

def add_lang_to_html(directory):
    # Loop through all files in the specified directory
    for file in os.listdir(directory):
        file_path = os.path.join(directory, file)

        # Only process .html and .htm files
        if os.path.isfile(file_path) and file.lower().endswith(('.html', '.htm')):
            with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
                content = f.read()

            # Only add lang="en" if it's not already there
            if "<html" in content and "<html lang=" not in content:
                new_content = content.replace("<html", '<html lang="fr"', 1)

                with open(file_path, "w", encoding="utf-8") as f:
                    f.write(new_content)

                print(f"✅ Updated: {file}")
            else:
                print(f"ℹ️ Skipped (already has lang or no <html>): {file}")

if __name__ == "__main__":
    add_lang_to_html(r"C:\Users\ijaco\web\fr")
